Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Catching exceptions as an expression while debugging Java in Eclipse IDE

Tags:

An everyday debugging situation for Java developers is that in which an Exception is thrown and then you need to dig into the debugger to find out what threw it. Usually you would try to set up some breakpoints before the exception is thrown and hope that you are able to determine the situation that leads up to that exception.

In Eclipse, a breakpoint may have an expression defined where it is only triggered when, for example, variable x equals value y. My question is, is it possible to define some kind of global expression where, once an exception is thrown, it is caught by the debugger, allowing the programmer to inspect all variables immediately? Ideally you would not have hit the catch block yet, Eclipse would catch the exception being raised and stop execution without changing the stack contents.

Is this possible or is it limited by the JVM?

like image 290
Héctor Ramos Avatar asked Feb 25 '09 20:02

Héctor Ramos


1 Answers

Another illustration: Eclipse Tip: Breakpoint on Exception

Eclipse let you set breakpoints based on where an Exception occurs.
You access the option via the "j!" http://help.eclipse.org/juno/topic/org.eclipse.jdt.doc.user/images/org.eclipse.jdt.debug.ui/elcl16/exc_catch.png icon in the debugging window (i.e., in the "Breakpoint View").

Add Java exception Window

The official help topic "Add Java Exception Breakpoint " has more on this.

  • The Uncaught Exception option is to suspend execution when an exception of the same type as the breakpoint is thrown in an uncaught location.
  • The Caught Exception option is to suspend execution when an exception of the same type as the breakpoint is thrown in a caught location.
  • do not forget the Exception Breakpoint Suspend on Subclass of this Exception:
    to suspend execution when subclasses of the exception type are encountered.
    For example, if an exception breakpoint for RuntimeException is configured to suspend on subclasses, it will also be triggered by a NullPointerException.

alt text

like image 90
VonC Avatar answered Oct 11 '22 03:10

VonC