Skip to content

Provide a way to distinguish between terminating error vs. non-terminating error #3158

Closed

Description

Add more details later

Steps to reproduce

Expected behavior

Actual behavior

Environment data

> $PSVersionTable

Activity

  1. apetitjean commented on Feb 23, 2017

    @apetitjean

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

  2. mklement0 commented on Jul 19, 2017

    @mklement0
    Contributor

    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.
    
  3. joeyaiello commented on Mar 13, 2019

    @joeyaiello
    Contributor

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

    /cc TylerLeonhardt Dongbo Wang (@daxian-dbw)

  4. SteveL-MSFT commented on Mar 15, 2019

    @SteveL-MSFT
    Member

    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

Metadata

Metadata

Labels

Issue-Enhancementthe issue is more of a feature request than a bugResolution-DuplicateThe issue is a duplicate.WG-Enginecore PowerShell engine, interpreter, and runtime

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions