private static ByteArrayOutputStream baos = new ByteArrayOutputStream() public static void main(String[] args) { ; try { System.out.println(1/0); } catch (Exception e) { toLog(e); } } private static void toLog(Exception e) { e.printStackTrace(new PrintStream(baos)); String exception = baos.toString(); System.out.println("baos:" + exception); }