Context
The baseline Error-Handling standard says fail fast, never swallow, and write helpful messages; Functions.md covers throw vs Write-Error; index.md sets $ErrorActionPreference = 'Stop'.
Gap
The PowerShell-specific error idioms are missing:
- Call cmdlets with
-ErrorAction Stop when you intend to trap them, so they raise terminating, catchable errors.
- Around native (non-cmdlet) commands, set
$ErrorActionPreference = 'Stop' and restore it afterward.
- Put the whole transaction inside the
try block rather than setting success flags to gate later code.
- Do not rely on
$? — it reports only whether the last command considered itself successful, with no detail.
- Avoid treating a
$null result as an error condition where a proper terminating error is available.
- In a
catch, copy $_ / $Error[0] into your own variable immediately, before later commands overwrite it.
Proposed change
Add a "PowerShell error handling" section to the PowerShell standard (Functions.md, or a dedicated page) that builds on the baseline Error-Handling page.
Source
PoshCode — Best Practices "Error Handling" (ERR-01…ERR-06).
Acceptance
The PowerShell standard captures the -ErrorAction Stop, transaction-in-try, avoid-$?, and copy-$_-in-catch rules.
Context
The baseline Error-Handling standard says fail fast, never swallow, and write helpful messages;
Functions.mdcoversthrowvsWrite-Error;index.mdsets$ErrorActionPreference = 'Stop'.Gap
The PowerShell-specific error idioms are missing:
-ErrorAction Stopwhen you intend to trap them, so they raise terminating, catchable errors.$ErrorActionPreference = 'Stop'and restore it afterward.tryblock rather than setting success flags to gate later code.$?— it reports only whether the last command considered itself successful, with no detail.$nullresult as an error condition where a proper terminating error is available.catch, copy$_/$Error[0]into your own variable immediately, before later commands overwrite it.Proposed change
Add a "PowerShell error handling" section to the PowerShell standard (
Functions.md, or a dedicated page) that builds on the baseline Error-Handling page.Source
PoshCode — Best Practices "Error Handling" (ERR-01…ERR-06).
Acceptance
The PowerShell standard captures the
-ErrorAction Stop, transaction-in-try, avoid-$?, and copy-$_-in-catchrules.