Search notes:

PowerShell: common parameter -errorVariable

Invoking a cmdLet with the common parameter -errorVariable causes an error message (if the cmdlet fails) to be stored in the specified variable.
Note that the argument to -errorVariable is a string, not a variable (-errorVariable err, not -errVariable $err).
As is also the case with the automatic variable $error, the type of the indicated variable is System.Collections.ArrayList whose elements store System.Management.Automation.ErrorRecord objects.
$item = get-item         `
   inexisting-item       `
  -errorVariable    err  `
  -errorAction      silentlyContinue


if ($err) {
   write-host $err
}
else {
   write-host "item $item found"
}
Github repository about-powershell, path: /language/cmdlet/parameter/common/errorVariable/get-inexisting-item.ps1

See also

The $error automatic variable.
Other common cmdlet parameters.

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:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/Windows/...', 1758779084, '216.73.216.41', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/Windows/PowerShell/language/cmdlet/parameter/common/errorVariable/index(61): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78