In C#, I can use the 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)?
Throwables don't get modified by throwing them. To update the stack trace you have to callfillInStackTrace(). Conveniently this method gets called in the constructor of aThrowable. - Robertthrow e;will lose the stacktrace. But not in Java. - Tim Goodman