How to ignore specific type of uncaught exception in Eclipse?

9.5k views Asked by At

I am using a third party library in my Java application. This third party library throws a custom uncaught exception at every application startup. The exception is harmless and only used for logging purposes internally to the third party library. Since this exception is not caught it causes my Eclipse IDE to switch into the debug perspective and suspend the thread execution everytime I start the application to inform me of the issue. I have to manually tell Eclipse to ignore this and just resume debugging every time. This is very annoying. I cannot change the third party library in order to fix this issue.

Is there a way to tell the Eclipse IDE to ignore a specific type of uncaught exception?

I tried "Step Filtering" but (I think) since the custom uncaught exception is not in the stack trace it is not being filtered out from the debugger. This is my first foray into Step Filtering so I could be using it wrong. Here is a sample stack trace.

Daemon Thread [Thread-13] (Suspended (exception CustomThirdPartyException)) 
    ThreadPoolExecutor$Worker.run() line: not available [local variables unavailable]   
    Thread.run() line: not available

EDIT:

jluzwick's work around of using our own logger to watch for uncaught exceptions after disabling all uncaught exceptions in Eclipse could technically work but it is not ideal and it's possible we could miss things if our logger is broken.

mazaneicha's Solution seemed to be on the right track but I could not get it to work exactly the way I wanted. This may be due to user error on my part.

jluzwick and mazaneicha both had possible work arounds to this issue but Konstantin Komissarchik had the "correct" answer in that this should be pushed back to the library's creators to fix. Sometimes a technical solution is not the right one.

6

There are 6 answers

2
Jeff On BEST ANSWER

An old thread, but figured I'd add a bit to it.

In at least Eclipse Indigo: In the Debug Perspective->Breakpoints view:

  1. Specify a breakpoint for Exceptions (and potentially subclasses) you want to pause on. This is done by clicking the "Add Java Exception Breakpoint". An icon that is a J and an exclamation point.
  2. Right click the breakpoint and select "Breakpoint Properties"
  3. Go to "Filtering"
  4. Specify the Class or Packages you want to ignore. This will add them to the list. Just be sure to uncheck them to delineate that it's exclusive (do not stop in the specified location)

I tend to use this so that I can specify NullPointerExceptions as a general exception breakpoint, but ignore packages that are from third party libraries.

3
Konstantin Komissarchik On

I would recommend trying to solve this in code instead. Find the place in your code where you are initializing this library and catch this exception instead of letting it propagate up the stack, which is not considered "normal" behavior.

2
jluzwick On

Have you tried this?

Go to Window->Preferences->Java->Debug

Under "Suspend Execution" uncheck "Suspend Execution on uncaught exceptions"

I'm not sure there's a way to disable for specific exceptions, but I could be wrong. There might possibly be a plugin that does it.

0
mazaneicha On

In Debug perspective, Breakpoints view, click on Java Exception Breakpoints (an icon with small letter J and exclamation mark, J!). In the appearing Add Java Exception Breakpoint window, you can find your annoying exception and uncheck "Suspend on Uncaught Exception" box.

0
Aron On

Contributing to Jeff's answer:

In Debug perspective right click on the suspended thread and choose 'Exclude Exception Location'. This way Eclipse adds the class the thread suspended on to the filtering list of the uncaught exception.

1
Galen Nare On

You sound like you need a simple try , catch.

 MyException e = new MyException;
 try {
       throw new e;
 } catch (MyException e) {
       e.printStackTrace();
 } 

This will allow the exception to be thrown, yet will ignore and let the program continue. If you want it to be logged to a file, use 'PrintWriter.println(e.printStackTrace());'

I hope you got what you needed, and happy coding!