debugjavaCritical
Rethrowing exceptions in Java without losing the stack trace
Viewed 0 times
javatracethelosingexceptionsstackwithoutrethrowing
Problem
In C#, I can use the
Is there something like this in Java (that doesn't lose the original stack trace)?
throw; statement to rethrow an exception while preserving the stack trace:try
{
...
}
catch (Exception e)
{
if (e is FooException)
throw;
}Is there something like this in Java (that doesn't lose the original stack trace)?
Solution
catch (WhateverException e) {
throw e;
}will simply rethrow the exception you've caught (obviously the surrounding method has to permit this via its signature etc.). The exception will maintain the original stack trace.
Code Snippets
catch (WhateverException e) {
throw e;
}Context
Stack Overflow Q#1097527, score: 707
Revisions (0)
No revisions yet.