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

强颜欢笑 提交于 2019-12-28 04:01:09

问题


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 Debug window will show that thread suspended and has the following data:

Thread [Thread-1] (Suspended (exception AssertionFailedException)) 
    ContactManager.addContact(String) line: 93  
    ContactManager$ContactDataCallback.dispatch(String, Element, ClientConnector) line: 118 
    PacketHandler.handle(FractusPacket) line: 173   
    ServerConnection.syncProcess(FractusMessage) line: 122  
    ServerConnection.run() line: 248    
    Thread.run() line: 636

However, the text that I'm looking for, such as: "Getter called outside realm of observable org.eclipse.core.databinding.observable.set.WritableSet@4b7361e2", is not available until I step through the exception (thus propagating it all the way up the stack) where it outputs the type of the exception, the text (which is the part that I want) and the stack trace.

How can I examine the "AssertationFailedException" (or any other exception) in order to get the message with which the exception was constructed? Of course I'm in the Debug perspective.


回答1:


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 !




回答2:


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




回答3:


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




回答4:


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.



来源:https://stackoverflow.com/questions/3453746/breakpoint-at-exception-in-eclipse-how-to-examine-exception-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!