Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't Visual Studio 2010 break on an unhandled exception?

When there is an exception thrown in my program, and it is unhandled, I expect the debugger to break in my program and show me what the problem is. This doesn't happen. Instead, my program simply exits, and debugging stops.

If I look at the debugging output, I can see my exception:

A first chance exception of type 'System.NullReferenceException' occurred in System.dll

I am using Visual Studio 2010, Visual Basic, writing a simple WinForms app. The code doesn't matter in this case... it happens with any exception that I've seen so far.

I've read a lot online about doing to the Debug menu and clicking Exceptions and enabling "break on unhandled user exception", but I don't see this option. I think this advice is for VS2008, and is no longer applicable.

I should also note that I'm not running any unit tests. I have never set them up. However, I have read that perhaps the unit tester is swallowing my exceptions?

Please advise me on how to change the behavior of Visual Studio, so I can track down these unhandled exceptions.

Thank you for your time.

like image 589
Brad Avatar asked Dec 29 '10 07:12

Brad


People also ask

How do I fix unhandled exception in Visual Studio?

In Visual Studio, when exceptions are thrown or end up unhandled, the debugger can help you debug these by breaking just like it breaks when a breakpoint is hit.

How do I enable Break on exception in Visual Studio?

In the Exception Settings window (Debug > Windows > Exception Settings), expand the node for a category of exceptions, such as Common Language Runtime Exceptions. Then select the check box for a specific exception within that category, such as System.

What happens with unhandled exception?

An unhandled exception occurs when the application code does not properly handle exceptions. For example, When you try to open a file on disk, it is a common problem for the file to not exist. The . NET Framework will then throw a FileNotFoundException.


1 Answers

The item may not be in the menu, which you can fix by customising the menu and adding the item to the debug menu.

You should also be able to get to the exceptions menu using CTRL + ALT + E

You need to tick the box in the "Thrown" column for Common Language Runtime exceptions (CLR)

like image 179
Fenton Avatar answered Sep 23 '22 21:09

Fenton