Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Breakpoint on an exception in visual studio

Tags:

How do I set a breakpoint on an exception? Ideally I want to be able to see the call stack and local variables from the code that threw the exception.

like image 636
Himadri Choudhury Avatar asked Apr 08 '11 15:04

Himadri Choudhury


People also ask

How do I add an exception breakpoint in Visual Studio?

When the debugger breaks, it shows you where the exception was thrown. You can also add or delete exceptions. With a solution open in Visual Studio, use Debug > Windows > Exception Settings to open the Exception Settings window. Provide handlers that respond to the most important exceptions.

How do I stop Visual Studio from breaking on exception?

To turn off stop on exceptions press " Ctrl + Alt + E ". This will open the Exceptions window . Untick "Common Language Runtime Exceptions - Thrown". That would prevent it from pausing from within the delegate, but not when it's rethrown on Wait .


2 Answers

I haven't used Visual Studio for 2 years, but from memory:

Ctrl + Alt + E 

Will bring exception management screen, make sure to check break on all exceptions, a must have imho :)

EDIT : My memory not that bad :) Just check Thrown on Common Language Runtime Exceptions if your are using .NET (CLR = .NET)

EDIT 2 : By the way, since exceptions are generally a bad coding practice and should be avoided as possible, i suggest to let that option enabled all the time. If some exceptions just can't be avoided (because of someone else, of course :D) just uncheck its type or ancestor in the exception type tree.

like image 166
Vincent Guerci Avatar answered Oct 05 '22 06:10

Vincent Guerci


The exact visual studio command name is Debug.Exceptions

Main Menu > Debug > Exceptions (when solution is open)

like image 40
Gishu Avatar answered Oct 05 '22 05:10

Gishu