This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
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 REST with Spring (video course) this week in the Spring 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:
subject: StackTrace
It's not a secret anymore!