Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 Options

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.

like image 312
brumScouse Avatar asked Sep 02 '25 08:09

brumScouse


1 Answers

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

like image 151
beehaus Avatar answered Sep 05 '25 00:09

beehaus