Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javaPack;
- public class ThrowsException {
- public static void divide() throws ArithmeticException, NumberFormatException{
- int a = Integer.parseInt("8b");
- int b = Integer.parseInt("0");
- int c = a/b;
- System.out.println("Result: " +c);
- }
- public static void main(String[] args) {
- try {
- divide();
- }
- catch(ArithmeticException e) {
- System.out.println("You cannot divide number by zero");
- }
- catch(NumberFormatException e) {
- System.out.println("Invalid number format");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement