Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ IDEA: How can I create an exception breakpoint that stops on all exceptions *except for* ClassNotFoundException? [duplicate]

I'd like to run my test suite in the debugger and break on any unexpected exception, but the Java classloaders throw lots of ClassNotFoundExceptions during normal operation.

So it would be nice if I could create an exception breakpoint that ignores ClassNotFoundExceptions and stops on everything else.

like image 429
Dan Berindei Avatar asked Jun 20 '11 08:06

Dan Berindei


People also ask

How do I stop exception breakpoint?

Remove breakpoints For non-exception breakpoints: click the breakpoint in the gutter. For all breakpoints: from the main menu, select Run | View Breakpoints Ctrl+Shift+F8 , select the breakpoint, and click Remove Delete .

How do I set conditional breakpoint in IntelliJ?

Add a condition to a breakpoint when debugging. Right-click on a breakpoint to configure its behavior: for instance, you can add a condition so that the execution will only be stopped when that condition is met.


1 Answers

This answer is almost the same as that of Mindas, but the details were enough for me to ignore his suggestion the first time around, and bother the Intellij support guys/girls (thanks Serge and Eugene):

  • Open the 'Breakpoints' window and go to the 'Exception Breakpoints' tab
  • Highlight and activate the 'Any exception' breakpoint
  • Activate only the 'Condition' Condition and type in the following:

    !(this instanceof java.lang.ClassNotFoundException) 

IDEA will remove 'java.lang' immediately (version 11.01), but it is required for this solution to work. If you don't use that, you will get a ClassNotFound popup box (irony oh irony).

I did find out that a lot of 'standard' libraries throw exceptions in their normal flow of operations. When you successfully ignore the ClassNotFoundException's, you will find that others suddenly appear. Nothing is ever easy.

like image 184
Jan Avatar answered Oct 16 '22 13:10

Jan