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