1. Check for exceptions: exceptions that will be found at compile Time. Custom Check exceptions inherit Excepiton.
2. Non-check Exception: The exception that is generated at run Time. Runtimeexcepiton and its subclasses, custom non-inspection exceptions to inherit Runtimeexcepiton.
3, Catch the exception: if there is a possible exception, the general compiler will give you the Try/catch box.
Try{//may produce an exception to the Statement}catch (Exception e) {//catch exception, The operation of the Exception}finally{//exception action to play, the statement that must be executed, such as the shutdown IO or something}
4, finally: not Necessary. typically, the statements inside the catch are executed before the finially is Executed. If the first sentence in the catch is return, then the finally is executed First.
5. Throws: If a function throws an inspection exception, it needs to be declared with throws declaration of the exception to be thrown for external capture and Processing.
6, Throw: throw an exception directly.
Package Exceptiontest;public class main {public static void main (String Args[]) {int a[] = new Int[2];a[0]=1;a[1]=2;//simple capture exceptions, and methods for using exception objects Try{system.out.println (a[3]);} Catch (Exception e) {System.out.println (e);} Finally{system.out.println ("exception! ");} External processing test throws an exception inside the try {test ();} catch (Exception e) {System.out.println (e);}} Static class MyException extends Exception{public myexception () {super ();} Public String toString () {return ' myexception ';}} If a function may throw an inspection exception, you must use the static inner class public static void Test () throws exception{myexception e = new MyException in the throws Declaration//static Method. (); Throw e;}}
Java Exception Review