Java a small tool for logging exception information
Package com.crm.mess.util;/** * * @author Liangrui * @2015/1/12 * */public class Exceptionslog {public synchronized St atic String Logclzinfo (Exception e) {stringbuffer sb = new StringBuffer (); Sb.append (E.getclass () + "" + e.getmessage () + "\ n"); stacktraceelement[] stacktraceelement = E.getstacktrace (); for (Stacktraceelement traceelement:stacktraceelement) { Sb.append ("\tat" + traceelement + "\ n");} return sb.tostring ();}}
Package Org.pass;public class Getclz {public static void main (string[] args) {C ();} public static void C () {try {int c = 10/0;} catch (Exception e) {String estr = Exceptionslog.logclzinfo (e); System.out.println ("Estr" + ":" + estr); E.printstacktrace ();}} /*output: * * java.lang.ArithmeticException:/by Zeroat org.pass.getclz.c (getclz.java:13) at Org.pass.GetClz.main (getclz.java:5) Estr:class java.lang.arithmeticexception/by zeroat org.pass.getclz.c (GetClz.java:13) at Org.pass.GetClz.main (GETCLZ.JAVA:5) * * * *
Java a small tool for logging exception information