项目中的问题代码
public static void main(String[] args) {
Main main = new Main();
try{
main.doBissness();
}catch(Exception e){
logger.error(e.getMessage());
}
main.doOtherBissness();
}
private void doOtherBissness(){
logger.debug("other bissness");
}
private void doBissness() throws AException{
String account = "LEON";
String cardNum = "XXX0288";
logger.debug("account is " + account);
logger.debug("card num is " + cardNum);
throw new AException("an exception");
}
为什么有问题
只给出了异常的message,没有调用栈信息,不好排错
出现异常后又继续走下面的业务逻辑,如果下面还有异常的话,不容易在日志中找到root cause.
修改之后的代码
public static void main(String[] args) {
Main main = new Main();
try{
main.doBissness();
}catch(Exception e){
logger.error(e.getMessage(),e);
return;
}
main.doOtherBissness();
}
private void doOtherBissness(){
logger.debug("other bissness");
}
private void doBissness() throws AException{
String account = "LEON";
String cardNum = "XXX0288";
logger.debug("account is " + account);
logger.debug("card num is " + cardNum);
throw new AException("an exception");
}