在我的代码库中,我有一些重试功能,它会将异常存储在变量中,并在最后将该变量中的异常抛出。类似于以下情况:
Exception exc = null;
while(condition){
try {
// stuff
} catch (Exception e){
exc = e;
}
}
if (e != null){
throw e;
}
现在,由于这是一个
throw e
语句而不是throw
语句,原始的堆栈跟踪已经丢失。是否有一种重新抛出异常并保留原始堆栈跟踪的方法,或者我需要重构我的代码以便使用throw
语句?
e
的StackTrace
属性中不会包含堆栈跟踪吗? - arconaut