2016-06-30
1 Throwing Exceptions manually
Throw exception; The parameter exception represents an object to throw, which is the Throwable class
Subclass, and can only be one.
2 Try Catch finally can be used in a nested set.
Packagecom.java1995;/*** 1 Throwing Exceptions manually *@authorAdministrator **/ Public classThrowtest { Public Static voidMain (string[] args) {throwtest T=Newthrowtest (); Try{t.test (); } Catch(Exception e) {//TODO auto-generated Catch blockSystem.out.println (E.getmessage ()); } } Public voidTest ()throwsexception{Throw NewException ("This is hand-thrown"); }}
Packagecom.java1995;/*** 2 try...catch...finally nested * Many more encountered in database connection pool *@authorAdministrator **/ Public classTrycatchfinallytest { Public Static voidMain (string[] args) {DoubleA=Math.random (); Try{ if(a>0.5) {System.out.println (a+ ", program does not error"); }Else{ Throw NewException (); } }Catch(Exception e) {System.out.println ("This is the object captured by the outer layer" +e); Try{a=1/0; }Catch(ArithmeticException E1) {System.out.println ("This is the object captured by the inner layer" +E1); }finally{System.out.println ("This is the finally block of the inner layer"); } }finally{System.out.println ("This is the outer finally block."); } }}
Resources
[1] Java Easy Start Classic tutorial "full version"
Java section 49th manually throwing exceptions