Java note 01: Exception Handling throwable class

Source: Internet
Author: User

In Java, errors are classified into two types based on the error nature: errors and exceptions.

In JavaProgramIf an exception occurs during execution, an exception object is generated. The generated exception object is passed to the Java runtime system. The exception generation and submission process is called throw exception.

When the system obtains an exception object during Java runtime, it will trace back to the method call stack layer by layer to find the exceptionCode. After finding a method that can handle this type of exception, the runtime system submits the current exception object to this method for processing. This process is called catch exception.

All exceptions in Java are generated by the throwable class subclass, and all Exception classes are subclasses of the throwable class or subclass. The throwable class is the direct subclass of the object class, and the error class and the exception class are the two direct subclasses of the throwable class.

1. Error class

The error class includes some serious system errors that cannot be processed by programs, such as memory overflow, virtual machine errors, and stack overflow. This type of error is generally related to hardware and has nothing to do with the program itself. It is usually handled by the system and cannot be captured or processed by the program itself.

The common subclass 1 of the error class is shown in.

Figure1 errorCommon subclass of A Class

2. exception class

Some exceptions cannot be anticipated during programming, such as exceptions of interruptions or illegal access. To ensure program robustness, Java requires that these exceptions be captured and processed.

The common subclass 2 of the exception class is shown in.

Figure2 exceptionCommon subclass of A Class

3. runtimeexception class

The runtimeexception class is a subclass of the exception class. The common subclass 3 of the runtimeexception class is shown in.

Figure3 runtimeexceptionCommon subclass of A Class

 

 

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.