New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide a way to distinguish between terminating error vs. non-terminating error #3158
Comments
That is definitely something that should be addressed! That makes just 10 years we struggle with that ;-) |
Related: #4292 Given the current capabilities:
Note: I'm using # Trigger a pipeline-terminating error; works the same with a script-terminating error (Throw).
$errCountBefore = $Error.Count
$terminatingErrorOccurred = $False
Try {
1 / 0
} Catch { # TRIGGERED by a TERMINATING ERROR - both pipeline-terminating and script-terminating
# Note: To also *output* the error, use Write-Error $_, but note that this
# *duplicates* the automatically generated $Error entry.
Write-Error $_
$terminatingErrorOccurred = $True
}
if ($terminatingErrorOccurred) { 'Terminating error occurred.' }
elseif ($Error.Count -gt $errCountBefore) { 'Non-terminating error occurred.' }
'---'
# Trigger a non-terminating error.
$errCountBefore = $Error.Count
$terminatingErrorOccurred = $False
Try {
# A non-terminating error prints its output to the error stream,
# irrespective of any enclosing Try/Catch handler.
Get-Item /NoSuch
} Catch { # NOT triggered by a NON-TERMINATING ERROR
$terminatingErrorOccurred = $True
}
if ($terminatingErrorOccurred) { 'Terminating error occurred.' }
elseif ($Error.Count -gt $errCountBefore) { 'Non-terminating error occurred.' } The above yields:
|
@SteveL-MSFT: I want this for Functions per our discussion on |
Dupe of #4781. Yes, this one is older, but the latter has more discussion. |
Add more details later
Steps to reproduce
Expected behavior
Actual behavior
Environment data
The text was updated successfully, but these errors were encountered: