tampurus

10 Exception handling

May 12th, 2022 (edited)
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.65 KB | None | 0 0
  1. class excp{
  2.     public static void main(String args[]){
  3.         int a,b,c;
  4.         try{
  5.             a=0 ; b=10 ;    
  6.             c = b/a;
  7.             System.out.println("This line won't be executed");
  8.         }
  9.         catch(ArithmeticException e)
  10.         {
  11.             System.out.println("Divide by zero");
  12.         }
  13.         System.out.println("After exception is handled");
  14.     }
  15. }
  16.  
  17. /*
  18. Output
  19.  
  20. */
  21.  
  22.  
  23.  
  24. class throoo{
  25.     static void check() throw ArithmeticException{
  26.         System.out.println("Inside check function");
  27.         throw new ArithmeticException("Demo");
  28.     }
  29.     public static void main(String args[]){
  30.         try
  31.             check();
  32.    
  33.         catch(ArithmeticException c)
  34.             System.out.println("Caught "+c);
  35.     }
  36.    
  37. }
  38.  
  39. // Ouput : not working
Add Comment
Please, Sign In to add comment