0 votes
1 view
in Java by (4.1k points)

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)?

1 Answer

0 votes
by (46.1k points)

You can try:

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.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Jul 9, 2019 in Java by Nigam (4.1k points)
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...