简体   繁体   中英

NetBeans and stop/break on all Exceptions?

I'm using NetBeans as my IDE for developing Android.

However, when I get an exception, Netbeans does not break on the exception as I expect it to.

I have checked the box "Stop on uncaught exceptions" that can be found in Options --> Java Debugger --> Stop on uncaught exceptions but that doesn't help.

Furthermore, where can I see the actual exception message? I don't see anything. I have no clue where and when an exception occurs, just that it does occur.

I've read some on the netbeans.org site about a bug in 6.9.1 that was fixed, but it doesn't seem to be fixed in 7.0 that I have.

The debugging window doesn't say anything useful at all, gives some form of stack trace that is pointless as it doesn't specify any of my own code.

I switched from Eclipse because that IDE sucks, NetBeans is much leaner, but the debugging needs to be fixed to be useful.

I have this problem when I use netbeans too. To get the exception message, I use try-and-catch. In the catch() statement, call a function that contains some code and put a breakpoint on it. Then when the exception is given your breakpoint in the catch statement will be called and you can read the information (error message, stack, etc.) from the Exception obect.

try
{
    // Doing something here
}
catch (Exception e1)
{
    // This is called when an exception occurs
    doSomething();   /// Put breakpoint here
}

UPDATE:

I am not sure if this will work for android but you could try entering a "New Breakpoint". When entering a new breakpoint to break on an exception, you need to know the exact package/class exception name. For example, if you want to catch a NullPointerException, then you go to Debug >> New Breakpoint to create a New Breakpoint and enter java.lang.NullPointerException into the Exception Class Name field in the Breakpoint Properties dialog. Choose whether to break on caught, uncaught or both, exceptions and it will hit a breakpoint if that type of exception ever occurs in the class/project.

I had such behavior where I had my source file that generated the exception NOT in "default package". When I moved everything to "default package" it started working fine and stop on exception automatically.

This answer actually also answers this question: https://stackoverflow.com/a/2671390/415551

To quote user Finbarr:

Go to debug > New Breakpoint (alternatively CTRL+SHIFT+F8). Change the breakpoint type to Exception in the top right hand drop down menu. Type java.lang.NullPointerException in the Exception class field. Choose whether to break on caught, uncaught or both.

Debug your code and watch the glorious auto breakpoint when the Exception is thrown.

Simply change java.lang.NullPointerException to java.lang.Exception to break on any error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM