jQuery in Action, 2nd edition*
The moose likes Java in General and the fly likes StackTrace Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "StackTrace" Watch "StackTrace" New topic


Justin Chu
Ranch Hand

Joined: Apr 19, 2002
Posts: 209
Why is it that sometimes StackTrace trace to the exact statement causing the exception, and other times it traces to the throw statement.
try {
someMethod(); // Trace to here.
} catch (Exception e){
throw e; // Trace to here.
Is it that when an exception is caught and thrown again, it'll lose the details within the try brackets?
John Dale
Ranch Hand

Joined: Feb 22, 2001
Posts: 399
I've never seen that. Are you sure you not throwing a new exception in the catch clause, like
try {whatever} catch(Exception e) { throw new Exception(); }
instead of
try {whatever} catch(Exception e) { throw e;}
In the API documentation for Throwable, a superclass of Exception, it says the stack trace is filled in when the Throwable is constructed, which matches my observations. However, the API documentation for Throwable also explains the use of fillInStackTrace() to update the stacktrace when you rethrow the exception.
Just to be sure, I tried your example:

And got
I agree. Here's the link: http://aspose.com/file-tools
subject: StackTrace
Similar Threads
Exception handling
Exception declaration
Explain me printStackTrace??
what is the emphasis on the finally block?