Exceptions (1)

Source: Internet
Author: User

 PackageChapterone.zidingyiyichang;/*** This program contains a comprehensive knowledge of the exception; * The order of execution is as shown in the label*/ImportJava.io.*;ImportJava.sql.*; Public classTestException { Public Static voidMain (String args[]) {Try{System.out.println ("Main1");//1. Print Main1Ma ();//2. Call the MA () method; 9. The Last Method Ma () throws a IOException exception that needs to be capturedSystem.out.println ("Main2"); } Catch(Exception e) {System.out.println ("Catch Exception in Main");//10. IOException exception for Capture Method Ma (), print catch Exception in main "System.out.println (E.getmessage ());//11. Then print E.getmessage (), which is SQL exception in MB        }    }     Public Static voidMA ()throwsIOException {Try{System.out.println ("MA1");//3. Print ma1;MB ();//4. Call the MB () method; 6. Method MB () throws the SqlException exception that needs to catch the exceptionSystem.out.println ("Ma2"); } Catch(SQLException e) {System.out.println ("Catch SQLException in Ma");//7. Capture method MB () throws the SQLException exception, print catch SQLException in MA; /c5>//exception in MB "            Throw NewIOException (E.getmessage ());//8. Another IOException exception is thrown, to output e.getmessage (), to be captured. }Catch(Exception e) {System.out.println ("Catch Exception in Ma");        System.out.println (E.getmessage ()); }    }     Public Static voidMB ()throwsSQLException {Throw NewSQLException ("SQL exception in MB");
//5. Throw SqlException exception, the specific exception is the print SQL exception in megabytes in detail. The information for E.getmessage () is "SQL exception in MB"; } /*** Result: * main1 * MA1 * catch SQLException in MA * Catch Exception in main * SQL Exception in MB*/ }

Exceptions (1)

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.