Java exception Exception class and its subclasses

Source: Internet
Author: User

C language with If...else ... To control exceptions,all exceptions in the Java language can be represented by a class, and different types of exceptions correspond to different subclass exceptions, and each exception corresponds to an object of the exception class.

Java exception handling is managed by 5 keyword try, catch, finally, throw, throws. The basic process is to use a try to wrap the statement to be monitored, if an exception occurs within a try, the exception is thrown, the catch catches the thrown exception and is processed, and finally will certainly complete the unfinished matter.

Practice:

 PackageCom.swift; Public classexception1{ Public Static voidMain (String args[]) {System.out.println ("========= Calculation begins ========="); Try{            intI=integer.parseint (args[0]); intJ=integer.parseint (args[1]); inttemp=i/J; System.out.println ("Calculation Result:" +temp); }Catch(ArithmeticException e) {System.out.println ("There was a mathematical anomaly" +e); }Catch(arrayindexoutofboundsexception e) {System.out.println ("An array exception has occurred" +e); }Catch(NumberFormatException e) {System.out.println ("Format exception has occurred" +e); }Catch(Exception e) {System.out.println ("Other exceptions" +e); }finally{System.out.println ("Regardless of whether there is an exception, I do." "); } System.out.println ("========= Compute End ========="); }}

Java exception Exception class and its subclasses

Related Article

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.