Nested Try-catch block--------exception handling (3)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.