Search notes:

PowerShell: the automatic variable $stackTrace

$stackTrace is an automatic variable whose type is string (!) which contains the stack trace for the most recent error.
Unfortunately, in a catch block, it does not indicate the source of the exception:
function func-a {
  func-b
}
function func-b {
   [int] $x = 'boom'
}
function func-c {
   func-d
}
function func-d {
   func-a
}

try {
   func-d
}
catch {
  write-host ($stackTrace.GetType().FullName)
  write-host '------'
  write-host $stackTrace
}
The output of the above code is:
System.String
------
   at System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
   at System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info)
   at System.ComponentModel.Int32Converter.FromString(String value, NumberFormatInfo formatInfo)
   at System.ComponentModel.BaseNumberConverter.ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, Object value)

See also

Other automatic variables, such as $error.
Error handling in PowerShell

Index