Java Exception class and its subclass, javaexception class

Source: Internet
Author: User

Java Exception class and its subclass, javaexception class

If... else... to control exceptions. All exceptions in the Java language can be represented by a class. 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 five keywords: try, catch, finally, throw, and throws. The basic process is to use try to wrap the statement to be monitored. If an exception occurs in try, the exception will be thrown. catch will capture and handle the thrown exception, finally will definitely complete the unfinished tasks.

Exercise:

Package com. swift; public class Exception1 {public static void main (String args []) {System. out. println ("========= computing start ========"); try {int I = Integer. parseInt (args [0]); int j = Integer. parseInt (args [1]); int temp = I/j; System. out. println ("Calculation Result:" + temp);} catch (ArithmeticException e) {System. out. println ("A mathematical exception occurred" + e);} catch (ArrayIndexOutOfBoundsException e) {System. out. println ("an array exception occurred" + e);} catch (Nu MberFormatException e) {System. out. println ("format Exception" + e);} catch (Exception e) {System. out. println ("Other exceptions" + e);} finally {System. out. println ("whether or not there is an exception, I will execute it. ");} System. out. println (" ========= computing end ======== ");}}

 

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.