The difference between error and exception in Java

Source: Internet
Author: User

The error class and the parent class of the exception class are all Throwable classes, and their differences are:

The error class generally refers to problems related to virtual machines, such as system crashes, virtual machine errors, insufficient memory, method call stack overflow, and so on. For this type of error caused by the application interruption, only the program itself can not recover and and prevention, encountered such an error, it is recommended to terminate the program.

The exception class represents an exception that a program can handle, and can be caught and possibly recovered. When you encounter such an exception, you should handle the exception as much as possible so that the program resumes running, rather than terminating the exception at will.

The Exception class is divided into Run-time exceptions (Runtime Exception) and checked exceptions (Checked Exception), run-time exceptions; Arithmaticexception,illegalargumentexception, the compiler can pass, but a run is terminated, the program does not handle run-time exceptions, this type of exception, the program will terminate. The exception that is checked is either a try ... Catch capture, either thrown with the throws clause declaration and handed over to its parent class, otherwise the compilation will not pass.

A common anomaly;

ArrayIndexOutOfBoundsException array subscript out of bounds exception,

Arithmaticexception Arithmetic exception if divisor is zero

NullPointerException NULL pointer exception

IllegalArgumentException Illegal parameter exception

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.