When there is a try block that does not have a corresponding exception to handle, the exception handling mechanism of its parent class is processed. If the exception handling mechanism of the parent class cannot be processed, the Java Run-time system throws an exception.
Example:
Class nest{public static void Main (String args[]) {//parent try block try{//child try Block1 try{ System.out.println ("Inside block1"); int b =45/0; System.out.println (b); } catch (ArithmeticException E1) {System.out.println ("exception:e1"); }//child try Block2 try{System.out.println ("Inside block2"); int b =45/0; System.out.println (b); } catch (arrayindexoutofboundsexception E2) {System.out.println ("exception:e2"); } System.out.println ("Just other statement"); } catch (ArithmeticException E3) {System.out.println ("arithmetic Exception"); System.out.println ("Inside parent Try Catch block"); } catch (ArrayIndexOutOfBoundsException e4) {System.out.println ("arrayindexoutofboundsexception"); System.out.println ("Inside parent Try Catch block"); } catch (Exception e5) {System.Out.println ("Exception"); System.out.println ("Inside parent Try Catch block"); } System.out.println ("Next statement."); }}
Output:
Inside block1exception:e1inside block2arithmetic exceptioninside parent Try Catch Blocknext statement:
Nested Try-catch block--------exception handling (3)