Skip to content
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

Closed
HemantMahawar opened this issue Feb 16, 2017 · 4 comments
Assignees
Labels
Issue-Enhancement the issue is more of a feature request than a bug Resolution-Duplicate The issue is a duplicate. WG-Engine core PowerShell engine, interpreter, and runtime
Milestone

Comments

@HemantMahawar
Copy link
Contributor

Add more details later

Steps to reproduce

Expected behavior

Actual behavior

Environment data

> $PSVersionTable
@HemantMahawar HemantMahawar self-assigned this Feb 16, 2017
@apetitjean
Copy link

That is definitely something that should be addressed! That makes just 10 years we struggle with that ;-)

@mklement0
Copy link
Contributor

mklement0 commented Jul 19, 2017

Related: #4292

Given the current capabilities:

Note: I'm using 1 / 0 as a stand-in for a pipeline-terminating error here:

# 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:

/Users/jdoe/Desktop/pg/pg1.ps1 : Attempted to divide by zero.
....
Terminating error occurred.
---
Get-Item : Cannot find path '/NoSuch' because it does not exist.
...
Non-terminating error occurred.

@joeyaiello
Copy link
Contributor

@SteveL-MSFT: I want this for Functions per our discussion on critical vs error logs.

/cc @TylerLeonhardt @daxian-dbw

@SteveL-MSFT SteveL-MSFT added Issue-Enhancement the issue is more of a feature request than a bug WG-Engine core PowerShell engine, interpreter, and runtime labels Mar 15, 2019
@SteveL-MSFT SteveL-MSFT added this to the 6.3-Consider milestone Mar 15, 2019
@SteveL-MSFT SteveL-MSFT added the Resolution-Duplicate The issue is a duplicate. label Mar 15, 2019
@SteveL-MSFT
Copy link
Member

SteveL-MSFT commented Mar 15, 2019

Dupe of #4781. Yes, this one is older, but the latter has more discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Enhancement the issue is more of a feature request than a bug Resolution-Duplicate The issue is a duplicate. WG-Engine core PowerShell engine, interpreter, and runtime
Projects
None yet
Development

No branches or pull requests

5 participants