The following is a demo of exception information output. You can learn to output the required information in exception handling, such as e. printStackTrace (), e. getMessage, or e. toString.
Public class testException
{
Public static void main (String [] args)
{
Try
{
Byte [] a = args [0]. getBytes ();
}
Catch (Exception e)
{
System. out. println ("logy prompts an exception stackTrace :");
E. printStackTrace ();
System. out. println ("logy prompts an exception message :");
System. out. println ("logy prompts an exception:" + e. getMessage ());
System. out. println ("logy prompts error e. tostring ");
System. out. println (e. toString ());
System. out. println ("logy prompts error e. getMessage. toString ");
System. out. println (e. getMessage (). toString ());
System. out. println ("details ");
StackTraceElement [] messages = e. getStackTrace ();
For (StackTraceElement I: messages)
{
System. out. println ("Class Name:" + I. getClassName ());
System. out. println ("file name:" + I. getFileName ());
System. out. println ("row number:" + I. getLineNumber ());
System. out. println ("method name:" + I. getMethodName ());
System. out. println ("information:" + I. toString ());
}
}
}
}
The running result is as follows:
Logy prompts an exception stackTrace:
Java. lang. ArrayIndexOutOfBoundsException: 0
At testException. main (testException. java: 8)
Logy prompts an exception message:
Logy error: 0
Logy error e. tostring
Java. lang. ArrayIndexOutOfBoundsException: 0
Logy error e. getMessage. toString
0
Details
Class Name: testException
File Name: testException. java
Row number: 8
Method Name: main
Information: testException. main (testException. java: 8)
E. getmessage <e. tostring <e. getStackTrace + e. tostring = e. printStackTrace