In C#, I can use the throw; statement to rethrow an exception while preserving the stack trace:
throw;
try{ ...}catch (Exception e){ if (e is FooException) throw;}
try
{
...
}
catch (Exception e)
if (e is FooException)
Is there something like this in Java (that doesn't lose the original stack trace)?
You can try:
catch (WhateverException e) { throw e;}
catch (WhateverException e) {
throw e;
It will just rethrow the exception you've passed (certainly the enclosing method has to allow this via its signature etc.). The exception will preserve the initial stack trace.