Java tutorial
//package com.java2s; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.PrintWriter; public class Main { public static String exception2String(Exception e) { ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream(); PrintWriter err = new PrintWriter(arrayOutputStream); e.printStackTrace(err); err.close(); try { arrayOutputStream.close(); } catch (IOException e1) { } return arrayOutputStream.toString(); } }