,

Java – Get Exception as String


public static String exceptionToString(Throwable throwable )
{
    try{
        StringWriter stringWriter = new StringWriter();
        throwable.printStackTrace(new PrintWriter(stringWriter));
        return stringWriter.toString();
    }catch(Exception e){
        // shouldn't happen but whatever
        return null;
    }
}


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *