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

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:51 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(51): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(66): id_of(Object(PDO), 'uri', '/notes/Windows/...') #2 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/Windows/...', 1788319035, '216.73.217.21', 'Mozilla/5.0 App...', NULL) #3 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Windows/PowerShell/language/variable/automatic/stackTrace(72): insert_webrequest() #4 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 51