3

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.

brumScouse
  • 3,166
  • 1
  • 24
  • 38
  • 1
    Take a look at http://stackoverflow.com/q/20912371/323582. I use the solution with *Debug-Error.ps1*, see one of the answers (mine). – Roman Kuzmin Apr 16 '15 at 17:33

2 Answers2

3

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
  • 415
  • 1
  • 4
  • 13
1

@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"
Doug
  • 6,446
  • 9
  • 74
  • 107