Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make the Visual Studio debugger stop when a handled exception occurs in C#

I'm trying to understand why and where an exception is thrown in my C# code. The problem is that all my code is in try-catch blocks, so debugger doesn't stop when it happens. Is there a way to explicitly tell it to stop?

like image 340
StuffHappens Avatar asked Mar 16 '11 15:03

StuffHappens


2 Answers

Just use the Ctrl+Alt+E shortcut to bring up the exceptions dialog. There you can select any exceptions for which you'd like Visual Studio to break.

like image 181
Sergi Papaseit Avatar answered Oct 23 '22 01:10

Sergi Papaseit


See How to: Break When an Exception is Thrown on MSDN.

To break execution when an exception is thrown

(1) On the Debug menu, click Exceptions.

Note If the Exceptions command does not appear on the Debug menu, you can add it. For more information, see To add the Exceptions command to the Debug menu.

(2)

In the Exceptions dialog box, select Thrown for an entire category of exceptions, for example, Common Language Runtime Exceptions.

-or-

Expand the node for a category of exceptions, for example, Common Language Runtime Exceptions, and select Thrown for a specific exception within that category.

like image 29
Justin Avatar answered Oct 23 '22 01:10

Justin