You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As someone fresh to Powershell that's a confusing distinction.
So would $erroractionpreference = "stop" work for my example above..?
i.e.
$erroractionpreference = "stop"
$someValue = .\server-task-1.ps1
# does not run the next two commands if server-task-1.ps1 exits with code != 0
.\server-task-2.ps1 -using $someValue
.\task-that-requires-everything-else-suceeded.ps1
but
$erroractionpreference = "stop"
$someValue = .\server-task-1.exe
# does run the next two commands _even though_ server-task-1.exe exits with code != 0
.\server-task-2.ps1 -using $someValue
.\task-that-requires-everything-else-suceeded.ps1
Reacted by Alexey Popovich, Axel Huebl and JordanRieger
$erroractionpreference = "stop" only works if Write-Error is called (such as an exception is raised). It doesn't do any checks against $lastexitcode. We can certainly look into adding another preference variable to throw an exception if $lastexitcode != 0.
Reacted by Paul D'Ambra, Troy Campbell, Jonas B. Andersen, mopadden, Chris Albrecht, Stepan Koltsov, Ian Norton, Alexander Köplinger, Timothee Guerin, Jan van Valburg and 14 more
Reacted by Chris Albrecht, Saquib Mian and Mateusz Łoskot
Since this is the first search result, linking the most recent thread on this RFC that I can find for anyone interested in implementing it PowerShell/PowerShell-RFC#277
Activity
SteveL-MSFT commentedon Mar 25, 2017
$erroractionpreference = "stop"is similar toset -e, except it only works against cmdlets and not native commandspauldambra commentedon Mar 27, 2017
As someone fresh to Powershell that's a confusing distinction.
So would $erroractionpreference = "stop" work for my example above..?
i.e.
but
SteveL-MSFT commentedon Mar 27, 2017
$erroractionpreference = "stop"only works ifWrite-Erroris called (such as an exception is raised). It doesn't do any checks against $lastexitcode. We can certainly look into adding another preference variable to throw an exception if $lastexitcode != 0.mopadden commentedon Mar 29, 2017
Would probably want to throw the exception only in a context where Powershell also sets $? to false as a result.
Throwing an exception in other situations where lastexitcode != 0 would not give a result equivalent to "set -e" in bash.
https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html
Edit: the idea is to throw an error on failure where the success/failure of an application is not tested.
mopadden commentedon Apr 7, 2017
Hi, i've done some work on this, can I ask for an assignment?
Equivalent of bash `set -e` (PowerShell#3415)
SteveL-MSFT commentedon Apr 11, 2017
mopadden consider it assigned, GitHub doesn't allow assigning to people without write access
7 remaining items
b-rad15 commentedon Jun 29, 2021
Since this is the first search result, linking the most recent thread on this RFC that I can find for anyone interested in implementing it PowerShell/PowerShell-RFC#277
daxian-dbw commentedon Nov 10, 2021
The PR that implements the RFC was already merged as an experimental feature: #15897
So, closing this issue.
nhooyr commentedon Dec 16, 2022
Is the equivalent of
set -euthen:Enable-ExperimentalFeature PSNativeCommandErrorActionPreferenceLinAGKar commentedon Apr 8, 2025
It seems like
$ErrorActionPreference = "Stop"makes it exit with 0 (success) on error, so it's not equivalent toset -ein that regard either.