In my codebase I have some retry functionality that stores an exception in a variable and at the end throws the exception in the variable. Imagine something like this
Exception exc = null;
while(condition){
try {
// stuff
} catch (Exception e){
exc = e;
}
}
if (e != null){
throw e;
}
Now, since this is a throw e
statement and not a throw
statement, the original stack trace is lost. Is there some way to do a rethrow that preserves the original stack trace, or will I need to restructure my code so I can use a throw
statement?