简体   繁体   中英

Can I "break when an exception is thrown" in Windows Powershell ISE?

Can I do this in the Powershell ISE like I can in Visual Studio:

Visual Studio Break On Exception 选项

Obviously I am not expecting the same dialogue and I'd hazard a guess I can wrap a try/catch around the part which calls out to the offending (nested) scripts - the bit of stuff I am interested in is nested deep. Id also assume that I can either go and open the existing file and slap a breakpoint in there.

However in the absence of doing that and as a nice convenience I would just like to be able to "break on any exception" because I am lazy.

In PowerShell there are automatic variables

The one you want to adjust is $ErrorActionPreference

$ErrorActionPreference = "stop"

Now when you hit any error within a commands that supports the -ErrorAction switch, the script will stop. It is worth noting that this is a native PowerShell action and you will still need the Try\Catch for any .NET and C# commands

@beehaus is on the right track, but with the wrong value. $ErrorActionPreference should be set to "break", per the documentation.

"Break - Enter the debugger when an error occurs or when an exception is raised."

aka

$ErrorActionPreference = "Break"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM