2016-06-30
1 Exception Declaration
A method does not handle the exception it produces, but instead calls the hierarchy to pass up,
Who calls this method, who will handle it.
Packagecom.java1995;/*** Exception statement: throws *@authorAdministrator **/ Public classTest { Public Static voidMain (string[] args) {System.out.println ("Main method begins execution"); Test T=NewTest ();//try{//T.test1 ();//}catch (ArithmeticException e) {//System.out.println (E.getmessage ());// }; //t.test2 ();T.test4 (); System.out.println ("Main Method End"); } Public voidTest1 ()throwsarithmeticexception{System.out.println ("Test1 () Start Execution"); System.out.println (1/0); System.out.println ("Test1 () execution Complete"); } Public voidTest2 ()throwsarithmeticexception{test1 (); } Public voidTest3 ()throwsarithmeticexception{test2 (); } Public voidtest4 () {Try{test3 (); }Catch(ArithmeticException e) {System.out.println (E.getmessage ()); } }}
Resources
[1] Java Easy Start Classic tutorial "full version"
Java section 48th, exception declarations in Java