Break When Exception Is Thrown

Visual Studio: How to break on handled exceptions?

With a solution open, go to the Debug - Windows - Exception Settings (Ctrl+Alt+E) menu option. From there you can choose to break on Thrown or User-unhandled exceptions.

EDIT: My instance is set up with the C# "profile" perhaps it isn't there for other profiles?

How to turn off Break when exception is thrown for custom exception types

In Visual Studio 2019, when the exception occurs, there will be an information dialog.

Just un-check "Break when this exception type is user-unhandled".

exception dialog

Break when exception is thrown

You are able to define the precise list of Exception you want to have a breakpoint on, even if those exceptions are uncaught (which should be the equivalent of "unhandled")

uncaught

Force break on any exception thrown in program

VS2015 and later: Go into Debug > Windows > Exception Settings and check the tick box against Common Language Runtime Exceptions (below the 'Break When Thrown' column header).

VS2013 and earlier: Go into Debug > Exceptions and check the Thrown box against Common Language Runtime Exceptions.

You may get a lot of noise this way though, as this will also break on exceptions thrown in libraries or inside the framework itself.

Do I have to break after throwing exception?

When you throw an exception, the next code to get executed is any catch block that covers that throw within the method (if any) then, the finally block (if any). You can have a try, a try-catch, a try-catch-finally or a try-finally. Then, if the exception is not handled, re-thrown by a catch block or not caught at all, control is returned to the caller. For example, you will get "Yes1, Yes2, Yes3" from this code ...

try
{
Console.WriteLine("Yes1");
throw (new Exception());
Console.WriteLine("No1");

}
catch
{
Console.WriteLine("Yes2");
throw;
Console.WriteLine("No2");
}
finally
{
Console.WriteLine("Yes3");
}

Console.WriteLine("No3");

eclipse debugger - breakpoint when exception is thrown on a specific place

I haven't try that, but when you click on "Breakpoint Properties" there is Filtering tab also, where you can specify locations, when stop or do not stop on the breakpoint.

Can I adjust the visual studio Break when an exception is thrown options programmatically?

This doesn't address your question directly, but there's a handy chord ctrl-D + E that brings up the debugging exceptions dialog. Ctrl+Alt+E will do the same thing.



Related Topics



Leave a reply



Submit