Error Handling
ERR-01 Use -ErrorAction Stop when calling cmdlets
ERR-02 Use $ErrorActionPreference = 'Stop' or 'Continue' when calling non-cmdlets
ERR-03 Avoid using flags to handle errors
try {
$continue = $true
Do-Something -ErrorAction Stop
} catch {
$continue = $false
}
if ($continue) {
Do-This
Set-That
Get-Those
}ERR-04 Avoid using $?
ERR-05 Avoid testing for a null variable as an error condition
ERR-06 Copy $Error[0] to your own variable
Last updated
Was this helpful?