字符串输出异常信息

private String getStackTraceAsString() {
    // StringWriter将包含堆栈信息
    StringWriter stringWriter = new StringWriter();
    //必须将StringWriter封装成PrintWriter对象,
    //以满足printStackTrace的要求
    PrintWriter printWriter = new PrintWriter(stringWriter);
    //获取堆栈信息
    e.printStackTrace(printWriter);
    //转换成String,并返回该String
    StringBuffer error = stringWriter.getBuffer();
    return error.toString();
}
可用于配置全局切面
posted @ 2021-09-06 17:25  DarkerbeS  阅读(50)  评论(0编辑  收藏  举报