Is there "Break on Exception" in IntelliJ?
A fast way to pop up the dialog is to press Ctrl + SHIFT + F8 (On Mac: Cmd + SHIFT + F8), then click over to the exception breakpoints tab. If that was the last tab you were viewing, it'll still be selected, making it easy to flick breaking on exceptions on and off.
This will cause IntelliJ to break at the point in the code (or library code) where the exception was raised. Specifically, you get a 'first chance' at exception handling, before the stack is walked looking for catch/finally blocks to execute.
TIP: Java tends to throw a lot of exceptions internally when loading classes, so this breaking on all exceptions can become quite tedious. The good news is that you can exclude certain types of exception using the condition field.
For example:
!(this instanceof java.lang.ClassNotFoundException)
You can chain multiple such conditions together with &&
.
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.
Run | View Breakpoints | Exception Breakpoints
In IntelliJ IDEA 14 go to:
Run -> View Breakpoints -> Check "Java Exceptions Breakpoints" -> Uncheck "Caught Exceptions"
If you do not uncheck Caught Exceptions
the execution will be stopped every time the Java Framework
throws an internal exception.