Hierarchy of exceptions for Java exceptions

Source: Internet
Author: User

One: Cause(1) recently in the Java Processing analysis of various data, encountered some anomalies, such as the parse () exception parseexception,valueof () numberformatexception IllegalArgumentException abnormalities, nullpointerexcetion indexoutofboundsexceptionfilenotfoundexception, etc.

(2) exception can not be arbitrarily captured, can not be arbitrarily write catch (***exceptionex) {}; only, it is possible to throw the corresponding exception before writing Catch , otherwise the extra catch Eclipse it will be an error.

in Java, exceptions are classified as checked exceptions, and run-time exceptions.

(3) The Order of multiple exception captures, first the subclass exception, then the parent class exception ... and finally the exception base class exception


Second: In Java, exceptions are classified as checked exceptions, and run-time exceptions.

both are in the exception class hierarchy. The following figure shows the inheritance relationship of the Java exception class .

( 1 ) pink is a checked exception (checkedexceptions), It must be try{}catch statement block captured throws clause declaration The exception being checked must be caught at compile time named

checkedexception   java compiler to check ,java The virtual machine also checks

( 2 ) The green exception is a run-time exception (runtime Exceptions), requires the programmer to analyze the code to determine whether to capture and processing, such as a null pointer, by 0 divide ... and declared as Error , it is a serious error , Business information is required to enter the

Line Special Handling , Error no snapping is required.

want to know more , Please refer to: Top 10Questions about Javaexceptions

Three:

(1) Today we see the Java question in the Polytechnic University:

When capturing multiple exceptions using multiple catch statements, Java specifies that the catch statement capturing exception must be at the end, as follows:

try {...}

catch (ClassCastException ex) {...}

catch (NumberFormatException ex) {...}

catch (Exception ex) {...} This sentence must be put at the end!

because Exception This is a couple of unusual parent or base classes! Those anomalies are his subclasses,Exception on the front and there is no chance, it catches all the anomalies.

That is , the order of multiple exception captures, first the subclass exception, then the parent class exception ... Finally, the exception base class exception.

Hierarchy of exceptions for Java exceptions

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.