The difference between error and exception in Java

Source: Internet
Author: User
Reprint: The difference between error and exception in 7990485java

The parent classes of the error class and the exception class are throwable classes, the difference being:

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

The exception class represents exceptions that the program can handle and can be captured and possibly recovered. If 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 arbitrarily.

The Exception class is also divided into runtime exceptions (runtime Exception) and checked exceptions (Checked Exception), run-time exceptions; Arithmaticexception,illegalargumentexception, the compilation can pass, but a run is terminated, the program will not handle runtime exceptions, such exceptions, the program will terminate. The exception to be checked is either a try ... Catch capture, either thrown with the throws clause declaration, to its parent class, or the compilation does not pass.

A common anomaly;

ArrayIndexOutOfBoundsException array Subscript out-of-bounds exception,

Arithmaticexception arithmetic exceptions such as dividing by zero

NullPointerException NULL pointer exception

IllegalArgumentException Illegal parameter exception

The difference between error and exception 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.