• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

StackTrace

 
Justin Chu
Ranch Hand
Posts: 209
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is it that sometimes StackTrace trace to the exact statement causing the exception, and other times it traces to the throw statement.
Eg.
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
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic