What are the exception types and differences in Java?????

Source: Internet
Author: User
Tags throwable

First, Introduction

According to the JDK documentation we can find the package where the exception is: Java.lang.Throwable, Throwable is the root class of all exception classes, error is wrong in Java.lang.error, and exception is abnormal in java.lang.exception can be found in

II. Overview of the error

When error class errors occur, the reason we need to associate this error is that most of the problems are related to virtual machines, such as insufficient memory, virtual machine errors, and so on. For these error messages to cause a program outage to stop, this behavior can only be repaired by modifying the code itself, and more advice is to terminate the program.

Iii. Overview of exception

When exception occurs, the program itself can handle the exception itself, which is the difference from the nature of the error, which cannot be handled by itself when an error occurs.

Exception has a lot of subclasses, so viewing the JDK documentation can draw exception exceptions and can be divided into Runntime exception and other exceptions:

    • RuntimeException exception occurs, it must be written code problems, such as the array out of bounds are not considered, NULL pointer exception does not take into account such information, so do not need to pass the throws processing, can be thrown directly, thrown to do not require the caller to handle, The caller can either handle it or not, and if it does not, it will be thrown up and then thrown to the virtual machine to stop the current thread.
    • When other exceptions occur, we can capture this exception (Try-catch) or throw the exception (throws) in the execution code, so once thrown, the caller must handle

Common Types of exceptions:

ArrayIndexOutOfBoundsException array Subscript out-of-bounds exception,

ClassNotFoundException type does not exist

NullPointerException NULL pointer exception

IllegalArgumentException Illegal parameter exception

What are the exception types and differences 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.