Java try catch 输出报错(包含类名、方法名、行号)


  • Java try catch 输出报错(包含类名、方法名、行号)

 

try {
    throw new Exception();
} catch (Exception exp) {
    String errorStr = "error: " + exp.getStackTrace()[0].getClassName() + "." + exp.getStackTrace()[0].getMethodName() + "() line:" + exp.getStackTrace()[0].getLineNumber() + "\n" + exp.toString();
    System.out.println(errorStr);
}

 

posted @ 2022-10-19 17:18  淡淡的晓山横雾  阅读(609)  评论(0)    收藏  举报