Breakpoint at exception in Eclipse - how to examine Exception object?

后端 未结 4 887
隐瞒了意图╮
隐瞒了意图╮ 2020-12-03 07:25

I feel like I\'m missing something very simple here. I have Eclipse set up to break on all exceptions. So, let\'s say that it breaks on an AssertationFailedException. The

相关标签:
4条回答
  • 2020-12-03 08:02

    As far as I can tell, it doesn't appear to be possible, which is kind of sad. For what it's worth, other IDEs I've used (IntelliJ IDEA, Oracle JDeveloper) seem to do a much better job at this.

    For example, IntelliJ IDEA has an option on exception breakpoints to log an expression to the console when an exception breakpoint is hit. In that expression, "this" is the thrown exception, so you can just log "this", and you get something like:

    Exception 'java.lang.IllegalStateException' occurred in thread 'main' at Silly.doThing(Silly.java:18)
    java.lang.IllegalStateException: dead jim
    

    It seems like supporting this would be a nice enhancement to the JDT... I couldn't find anything that looked related in their bug database: https://bugs.eclipse.org/bugs/buglist.cgi?quicksearch=exception+breakpoint

    0 讨论(0)
  • 2020-12-03 08:07

    In the debug view, click on the thread producing the exception.

    0 讨论(0)
  • 2020-12-03 08:09

    You can see the Type of the exception in debug perspective in the breakpoints tab. I have attached a screenshot for your reference. There I had NullPointerException, which is been shown in the breakpoints tab. enter image description here

    0 讨论(0)
  • 2020-12-03 08:18

    There is an option in the Eclipse Preferences that allows inspecting of the thrown exception:

    Check Java -> Debug -> Open popup when suspended on exception

    With this option there will be a popup allowing inspection of the exception.

    Strange that this option is not checked by default as it is very useful !

    0 讨论(0)
提交回复
热议问题