Digital_ghost

Exception handling

Jan 30th, 2023
682
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.35 KB | None | 0 0
  1. class Main {
  2.   public static void main(String[] args) {
  3.     try {
  4.       // code that generates exception
  5.       int divideByZero = 5 / 0;
  6.     }
  7.  
  8.     catch (ArithmeticException e) {
  9.       System.out.println("ArithmeticException => " + e.getMessage());
  10.     }
  11.    
  12.     finally {
  13.       System.out.println("This is the finally block");
  14.     }
  15.   }
  16. }
Advertisement
Add Comment
Please, Sign In to add comment