public class UsingChainedExceptions
1: // Fig. 13.8: UsingChainedExceptions.java
2: // Demonstrating chained exceptions.
3:
4: public class UsingChainedExceptions
5: {
6: public static void main( String args[] )
7: {
8: try
9: {
10: method1(); // call method1
11: } // end try
12: catch ( Exception exception ) // exceptions thrown from method1
13: {
14: exception.printStackTrace();
15: } // end catch
16: } // end main
17:
18: // call method2; throw exceptions back to main
19: public static void method1() throws Exception
20: {
21: try
22: {
23: method2(); // call method2
24: } // end try
25: catch ( Exception exception ) // exception thrown from method2
26: {
27: throw new Exception( "Exception thrown in method1", exception );
28: } // end try
29: } // end method method1
30:
31: // call method3; throw exceptions back to method1
32: public static void method2() throws Exception
33: {
34: try
35: {
36: method3(); // call method3
37: } // end try
38: catch ( Exception exception ) // exception thrown from method3
39: {
40: throw new Exception( "Exception thrown in method2", exception );
41: } // end catch
42: } // end method method2
43:
44: // throw Exception back to method2
45: public static void method3() throws Exception
46: {
47: throw new Exception( "Exception thrown in method3" );
48: } // end method method3
49: } // end class UsingChainedExceptions
50:
51: /**************************************************************************
52: * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and *
53: * Pearson Education, Inc. All Rights Reserved. *
54: * *
55: * DISCLAIMER: The authors and publisher of this book have used their *
56: * best efforts in preparing the book. These efforts include the *
57: * development, research, and testing of the theories and programs *
58: * to determine their effectiveness. The authors and publisher make *
59: * no warranty of any kind, expressed or implied, with regard to these *
60: * programs or to the documentation contained in these books. The authors *
61: * and publisher shall not be liable in any event for incidental or *
62: * consequential damages in connection with, or arising out of, the *
63: * furnishing, performance, or use of these programs. *
64: *************************************************************************/