Java exceptions and compiled with abnormal into operation. An exception only to be found in the program is running is running. Compiled abnormalities can be found at compile time, and have to deal with. Custom exceptions are usually compiled an exception.
Second, the statement and throw an exception
1 2 3 4
Method name () throws Exception Type 1 , Type exception 2 { the throw exception object }
Third, the capture and handle exceptions
Call declares compiled unusual methods must be abnormal capture and processing
Use try ... catch catch unhandled exceptions
Finally block of code must be performed
Or continue to call the method declaration throws an exception, handled by the upper caller
the try { // code may throw exceptions } catch (IOException E) { // IO exception handling } catch (Exception E) { // plurality of nested catch, the latter type of exception range greater // other exception handling } a finally { // statement will be executed }
//JDK1.7 above new features the try {
} The catch (Exception Type 1 | exception type 2 E) { // an abnormal and abnormal 2 can not have inheritance
}
Abnormal commonly used method
getMessage () Gets the exception information
printStack () method call stack print anomalies
Fourth, the custom exception
Custom exception must be directly / indirectly inherit Exception class
Usually in the Java predefined exception can not meet the requirements, it will be custom exception.