Verbose logging of Java exception (Exception) information

Source: Internet
Author: User

Verbose logging of Java exception (Exception) information
Get more information on exception
The following three methods are all for getting the details of the exception, and perhaps the exception details are returned as strings, preserving the style of the stack heap


Method One:

public static string Getexceptionallinformation (Exception ex) {string sOut = "";        Stacktraceelement[] trace = Ex.getstacktrace ();        for (Stacktraceelement s:trace) {sOut + = "\tat" + S + "\ r \ n"; } return sOut; }

Method Two:

Public static string getexceptionallinformation_01 (Exception ex)  {          bytearrayoutputstream out = new bytearrayoutputstream ( );          printstream pout = new printstream (out);          ex.printstacktrace (pout);          string ret = new string (Out.tobytearray ());          pout.close ();          Try {              out.close ();          } catch  (exception e)  {          }         return  ret; }

Method Three:

private static String tostring_02 (Throwable e) {stringwriter SW = new StringWriter ();              PrintWriter pw = new PrintWriter (SW, True);              E.printstacktrace (PW);               Pw.flush ();              Sw.flush ();      return sw.tostring (); }


Verbose logging of Java exception (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.