Usually use E.getmessage () or e.printstacktrace ();
The first kind of the exception to throw the new RuntimeException ("Exception"), can only get an exception of 2 words.
The second type of e.printstacktrace (); Just prints and does not return any data.
While the server is generally clustered or other methods of deployment, view the log is too cumbersome, you can stack information into a string and other types, and then save to the database, placed in the hidden field of the page for easy viewing.
There are 3 ways to choose from:
Method One:
package name.xu;public class callstack { public static VOID&NBSP;PRINTCALLSTATCK () { throwable ex = new throwable (); stacktraceelement[] Stackelements = ex.getstacktrace (); if (stackelements != null) { for (int i = 0; i < stackelements.length; i++) { System.out.print (Stackelements[i].getclassname () + "/t"); system.out. Print (Stackelements[i].getfilename () + "/t"); system.out.print (Stackelements[i].getlinenumber () + "/t"); system.out.println (StackElements[i]. Getmethodname ()); system.out.println ("-----------------------------------"); } } } }
Method Two:
Exception e = new Exception ("This is a log"); E.printstacktrace ();
Method Three:
String fullstacktrace = Org.apache.commons.lang.exception.ExceptionUtils.getFullStackTrace (e)
Method Four:
Thread.CurrentThread (). Getstacktrace ()
Personal recommendation, method One, reason: easy to use, fast
Java Exception stack information turn string