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)