Java 获取异常堆栈信息

一个公共方法:

public class LogUtils
{
    /**
     * 获取异常的调用堆栈信息。
     * 
     * @return 调用堆栈
     */
    public static String toStackTrace(Exception e)
    {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        try
        {
            e.printStackTrace(pw);
            return sw.toString();
        }
        catch(Exception e1)
        {
            return "";
        }
    }
}

转载于:https://www.jianshu.com/p/818f37dfbffc

猜你喜欢

转载自blog.csdn.net/weixin_34378045/article/details/91073065