ya_zay4eg

level_09_runtimeException

Jan 11th, 2015
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.66 KB | None | 0 0
  1. class ExceptionExampleOriginal
  2. {
  3.  
  4.     public static void main(String[] args)
  5.     {
  6.         System.out.println("main begin");
  7.         try
  8.         {
  9.             System.out.println("main before call");
  10.  
  11.             method1();
  12.  
  13.  
  14.             System.out.println("main after call");
  15.         }
  16.         catch (RuntimeException e)
  17.         {
  18.             String s = e.getMessage();
  19.             System.out.println(s);
  20.         }
  21.         System.out.println("main end");
  22.     }
  23.  
  24.     public static void method1()
  25.     {
  26.         System.out.println("method1 begin");
  27.         method2();
  28.        
  29.         System.out.println("method1 end");
  30.     }
  31.  
  32.     public static void method2()
  33.     {
  34.         System.out.println("method2");
  35.         String s = "Message: Unknown Exception";
  36.         throw new RuntimeException(s);
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment