Run or compiler, the error collectively generated an exception (also called Bug), abnormal divided into Error, Exception Error encountered when the program does not handle this exception because this anomaly is the abnormal physical device, such as inadequate memory like; and the program can run uncaught exception is an exception compile time and run time exceptions, these can be adjusted by modifying the code back repaired
JVM's default handling program
If the program there is a problem, we did not do any treatment, JVM will do eventually default handler
- The output unusual name, location and cause of the abnormal exception occurred in the console
- Program to stop execution
FIG structural abnormalities
Runtime exception
Also known as checked exceptions
RuntimeException and its subclasses are runtime class. Abnormal is run when the program is run by the Java Virtual Machine to automatically capture process.
ArithmeticExceptio arithmetic exception
ClassCastException type conversion exception
IndexOutOfBoundsException subscript bounds exception
NullPointerException null pointer exception
NumberFormatException abnormal digital format
Compile-time anomaly
Also called unchecked exceptions
in addition to the RuntimeException class and its subclasses, other subclasses are exceptions when you compile
use:
1, using the try ... catch statement to capture the abnormal processing, treatment can write their own
2, using the throws keyword to declare an exception is thrown, let the caller their own treatment, treatment can not write
Throws and throw the difference
throws
- In a later statement method, with the class name is unusual
- Represents an exception is thrown, handled by the caller of the method
- One possibility indicating the occurrence of abnormality, not necessarily these exceptions occur
thorw
- Used in vivo, with the exception object name is
- It represents an exception is thrown, the statements in vivo treatment
- Execution must throw throw some abnormality