/** * @authorWangyunhan *@throwsException*/ Public Static voidMain (string[] arg?s)throwsException {testabove (); } Public Static voidTestException ()throwsException {Try{System.out.println (10%0); }Catch(ArithmeticException R) {System.out.println ("Catch function Exception" +r.tostring ()); } Catch(Exception e) {Throw NewException ("TestException () method Exception" +e.tostring ()); } } Public Static voidTestabove ()throwsException {Try{testexception (); System.out.println ("Execute test Above"); }Catch(Exception e) {Throw NewException ("Testabove () method execution occurred exception" +e.tostring ()); } }
The result of the above code execution
Catchjava.lang.ArithmeticException:/by Zerotest above execute
Analysis:
- One method captures multiple exceptions, and if the exception has been caught, then the catch does not execute
- Exception if a catch has been caught and no exception is thrown, the method does not throw an exception
Handling mechanisms for capturing multiple exceptions in Java methods