public void addTitleRow() throws SQLException{
ResultSet rs = stmt.executeQuery("SELECT * FROM ANY")
log.info ? }
如何记录声明在方法签名中抛出的exception
?我正在使用 log4j2
答案 0 :(得分:1)
您必须先捕获异常才能记录它。你可以抑制它,或者如果你愿意,可以稍后再重新抛出它。
以下是代码段:
重新抛出例外:
try {
/* Do Something Here */
} catch (Exception ex) {
log.error("An Exception Has Occurred!", ex);
throw ex;
}
抑制例外:
try {
/* Do Something Here */
} catch (Exception ex) {
log.warn("An Exception Has Occurred!", ex);
}