ya_zay4eg

level_09_03_example_different Exception

Jan 11th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.95 KB | None | 0 0
  1. public class ExceptionExample2
  2. {
  3.     public static void main(String[] args)
  4.     {
  5.         System.out.println("Program starting.");
  6.         try
  7.         {
  8.             System.out.println("Before method1 calling.");
  9.            
  10.             method1();
  11.            
  12.             System.out.println("After method1 calling. Never showed.");
  13.         }
  14.         catch (NullPointerException e)
  15.         {
  16.             System.out.println("Reference is null. Exception caught.");
  17.         }
  18.         catch (ArithmeticException e)
  19.         {
  20.             System.out.println("Divided by zero. Exception caught.");
  21.         }
  22.         catch (Exception e)
  23.         {
  24.             System.out.println("Any other errors. Exception caught.");
  25.         }
  26.         System.out.println("Program still running.");
  27.         }
  28.         public static void method1()
  29.         {
  30.             int a = 100;
  31.             int b = 0;
  32.             System.out.println(a / b);
  33.         }
  34.         }
Advertisement
Add Comment
Please, Sign In to add comment