Is there “Break on Exception” in IntelliJ?

2019-01-20 23:46发布

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.

5条回答
Animai°情兽
2楼-- · 2019-01-20 23:48

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.

查看更多
叼着烟拽天下
3楼-- · 2019-01-20 23:51

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.

查看更多
走好不送
4楼-- · 2019-01-20 23:55

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 &&.

enter image description here

查看更多
叛逆
5楼-- · 2019-01-20 23:58

Run | View Breakpoints | Exception Breakpoints

查看更多
Root(大扎)
6楼-- · 2019-01-21 00:13

If you click on the little "+" sign in the upper left corner, you can add a new breakpoint. If you select Exception Breakpoint, you get a little dialog where you can enter the exception class to break on (in case you don't want to break on all exceptions).

查看更多
登录 后发表回答