字符串输出异常信息

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();
}
可用于配置全局切面
上一篇:printStackTrace和getStackTrace和fillInStackTrace


下一篇:java 读写UTF-8文件的方法