我可以以某种方式在方法中包含这段代码吗
if (!printStackTrace_printed) {
ex.printStackTrace();
printStackTrace_printed=true;
}
logStoreException(ex);
throw new Exception(ex.getMessage());
并在每个 catch 块内调用它并传递正确的参数ex或npe
catch (RationalTestException ex) {
if (!printStackTrace_printed) {
ex.printStackTrace();
printStackTrace_printed=true;
}
logStoreException(ex);
throw new Exception(ex.getMessage());
}
catch (NullPointerException npe) {
if (!printStackTrace_printed) {
npe.printStackTrace();
printStackTrace_printed=true;
}
logStoreException(npe);
throw new Exception(npe.getMessage());
}
catch (Exception ex) {
if (!printStackTrace_printed) {
ex.printStackTrace();
printStackTrace_printed=true;
}
logStoreException(ex);
throw new Exception(ex.getMessage());
}