Java exception information integrity control

Source: Internet
Author: User

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

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.