Advertisement
karlakmkj

Exception with throws

Sep 6th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.52 KB | None | 0 0
  1. package javaPack;
  2.  
  3. public class ThrowsException {
  4.  
  5.     public static void divide() throws ArithmeticException, NumberFormatException{
  6.         int a = Integer.parseInt("8b");
  7.         int b = Integer.parseInt("0");
  8.         int c = a/b;
  9.         System.out.println("Result: " +c);
  10.     }
  11.    
  12.     public static void main(String[] args) {
  13.         try {
  14.             divide();
  15.         }
  16.         catch(ArithmeticException e) {
  17.             System.out.println("You cannot divide number by zero");
  18.         }
  19.         catch(NumberFormatException e) {
  20.             System.out.println("Invalid number format");
  21.         }
  22.     }
  23. }
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement