Skip to content

Set-StrictMode should cause errors to terminate execution. #9591

Description

Set-StrictMode should cause errors to terminate execution.

In most languages with exceptions, an unhandled exception causes the program to terminate. However, Powershell defaults to continuing on when an unhandled exception occurs.

As a result, I think it is currently widely considered a best practice to begin all scripts with:

$ErrorActionPreference = "Stop"
Set-StrictMode -Version 3.0

Proposed change

This should be equivalent to the above:

Set-StrictMode -Version 4.0 

There is also some discussion in PowerShell/PowerShell-RFC#88 .
I think that whatever the mechanism for causing non-zero exit codes to halt execution, that should also be included in StrictMode.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Enhancementthe issue is more of a feature request than a bugResolution-No ActivityIssue has had no activity for 6 months or more

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions