5

I have exceptions thrown in my java code when an error occurs. I then run the code using jdb so when the exception occurs, I can see the state that the code is in and debug. For all exceptions that I throw, I put in a useful string message. However, when jdb catches the exception, it doesn't print this string along with it. How do I print this string?

I have googled and searched and read the documentation but I can't figure out how.

If I have the test class:

public class Test{
    public static void main(String[] args){
        throw new IllegalArgumentException("How do I view this string through jdb?");
    }
}

And run it through jdb:

$ jdb Test
Initializing jdb ...
> run
run Test
Set uncaught java.lang.Throwable
Set deferred uncaught java.lang.Throwable
> 
VM Started: 
Exception occurred: java.lang.IllegalArgumentException (uncaught)"thread=main", Test.main(), line=3 bci=9

main[1] 
user2019811
  • 53
  • 1
  • 4

1 Answers1

-1

Check out the JDB "catch" command, for example "catch IllegalArgumentException". Per the JDB docs, it will cause the debugger to break when the exception is thrown so that you can probe into the details. This document on debugging does a nice job explaining some of the downsides to being dependant on "print" statements, and also references the JDB "catch" functionality.

Tyson
  • 1,685
  • 15
  • 36
  • 1
    The only problem is that I throw different exceptions depending on the error IllegalArgument, IllegalState, AssertionError etc. The code base is not exactly small, and I don't remember all the exceptions I throw – user2019811 Mar 23 '13 at 14:06