Exceptions in Java

Source: Internet
Author: User

Exception: An event that interrupts the normal instruction flow and is the object generated by the JVM virtual machine

exceptions are generated when the program is run , and are not related to compilation

Class test{public      static void Main (String args[]) {           System.out.println (111111);           int i = 1/0;           System.out.println (222222);      }}

The above is an arithmetic exception (a subclass of Runtimeexcepiotn), and when an exception occurs, the statement following the exception is no longer executed.

Classification of exceptions: classes provided by the JDK

All exception classes are subclasses of Throwable. Throwable two direct sub-classes are exception and error. Error refers to the JVM's errors, and once an error occurs, the JVM shuts down and the program ceases to exist, and the programmer is powerless to error. Exception can also be divided into uncheckexception and checkexception. Uncheckexception includes subclasses of Runtimeexcepiotn and Runtimeexcepiotn. The immediate subclasses of exception belong to Checkexception except for Runtimeexcepiton.

The difference between uncheckexception and checkexception:

When a program is likely to appear checkexception, the compiler will force you to handle and capture code that might appear to be an exception.

Handling Exceptions using try...catch...finally snapping

Class Test{public static void Main (String args[]) {System.out.println (111111); try{system.out.println (222222); int i = 1/ 0; System.out.println (333333);} catch (Exception e) {e.printstacktrace (); System.out.println (444444);} Finally{system.out.println (555555);} System.out.println (666666);}}

When the program is running an exception is transferred to the catch to execute, if there is no exception to execute the code in the catch, and finally the code regardless of whether an exception will be executed.

Exceptions in Java

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.