Java exception capture and exception handling

Source: Internet
Author: User

Tag: Trace ice handles the Exce RGS Ima style method without

Try{will produce an exception code

}catch (Type E of the exception that occurred) {

The method of post-processing of abnormal occurrence

}

Once an exception is present and no exception is handled, the program is interrupted.

      public static void Main (string[] args) {
try {
int num = 10/0;
SYSTEM.OUT.PRINTLN (num);
} catch (ArithmeticException e) {
System.out.println ("There's an exception!" ");
}
}

This exception is thrown when an operating condition of an exception occurs. For example, an integer "divided by 0" throws an instance of this class.

        public static void Main (string[] args) {try {int num = 10/0; SYSTEM.OUT.PRINTLN (num);} catch (ArithmeticException e) {System.out.println ("there is an exception!") "); System.out.println (E.getmessage ());//Print exception Information System.out.println (E.tostring ());//Print exception type and exception information E.printstacktrace (); /print Exception type and exception information, and print out the wrong location}}

Java exception capture and exception handling

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.