Java a small tool for logging exception information

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.