Breakpoint on an exception in visual studio

13,392

Solution 1

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.

Solution 2

The exact visual studio command name is Debug.Exceptions

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

Solution 3

Also, make sure you're running in debug mode and that debugging is enabled in the project properties or else all the breakpoints in the world will count for nothing.

(Depending on your environment you can also click on the margin outside the code source to insert a breakpoint via mouse action)

Share:
13,392

Related videos on Youtube

Himadri Choudhury
Author by

Himadri Choudhury

Trying to be a better programmer.

Updated on April 16, 2020

Comments

  • Himadri Choudhury
    Himadri Choudhury about 4 years

    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.

  • abatishchev
    abatishchev about 13 years
    Exceptions ARE NOT bad coding practice
  • Vincent Guerci
    Vincent Guerci about 13 years
    @abatishchev Added generally to my answer, seriously, I've seen enough atrocities implicating bad exception use. :)
  • kevinthompson
    kevinthompson almost 8 years
    In Visual Studio 2015 it's Main Menu > Debug > Windows > Exception Settings.

Related