Get exception information in Java

Get exception information in Java

During development, we may need to record exception information to other places, and we can use the following code to output exception information

    public static String getExceptionMessage(Throwable e) {
    
    
        StringWriter stringWriter = new StringWriter();
        PrintWriter printWriter = new PrintWriter(stringWriter, true);
        e.printStackTrace(printWriter);
        printWriter.flush();
        stringWriter.flush();
        return stringWriter.toString();
    }

Guess you like

Origin blog.csdn.net/daiyi666/article/details/117295020