Is there "Break on Exception" in IntelliJ?

Viewed 88771

Is there feature that will automatically break debugging on first exception occurrence?

So we

  1. start application
  2. do something that throw exception
  3. got IntelliJ popped up highlighted line where exception occurred.
6 Answers

Run | View Breakpoints | Exception Breakpoints

In newer versions of intellij, it is under Run > View Breakpoints.

Then you can check Java Exception Breakpoints -> Any Exception.

A good way to debug the exceptions is to use your main app package and the wild card .*. This way you skip all the other libraries exceptions, since most of the times you are looking for exceptions throwed by your app and not by any other library (which can be a lot of exceptions).

As an example showed in the image i use com.gs.mercury.* to break every time the app throws an exception. If you use exceptions for what they are for (to handle exceptional cases and not to handle the flow of normal situations) you will only stop when you reach the desired exception almost all the time.

PD. answer added just to point out the pretty useful Catch class filter.

Breakpoints

Yes, there is. You need to define an exception breakpoint (it can be "Any exception") in the breakpoints dialog in IntelliJ IDEA.

The exceptions can be filtered by condition or class if desired, or by whether you are interested in caught or uncaught exceptions.

Related