Very Simple Exception Handle Program in Java

  1. import java.io.*;  
  2.   
  3. public class exceptionHandle{  
  4.     public static void main(String[] args) throws Exception{  
  5.         try{  
  6.             int a,b;  
  7.             BufferedReader in = new BufferedReader(new InputStreamReader(System.in));  
  8.             a = Integer.parseInt(in.readLine());  
  9.             b = Integer.parseInt(in.readLine());  
  10.         }  
  11.         catch(NumberFormatException ex){  
  12.             System.out.println(ex.getMessage() + " is not a numeric value.");  
  13.             System.exit(0);  
  14.         }  
  15.     }