Menu
Question Index
...

What will be the output of the following program?

public class Define {
    public static void main(String s[]) {
        process(1);
    }
    public static void process(int input) {
        try {
            process2(input);
        } catch (Exp1 ex) {
            System.out.println("Exception occurs");
        }
    }
    public static void process2(int input) throws Exp1 {
        if (input == 1) {
            throw new Exp1(25);
        }
    }
}
class Exp1 extends Exception {
    int errorCode;
    public Exp1(int a) {
        errorCode = a;
        System.out.println("Exception A occured with error code = " + errorCode);
    }    
}


Exception occurs
Exception occurs
Exception A occured with error code = 25
Exception A occured with error code = 25
Exception occurs
Exception A occured with error code = 25
Compilation Error or Runtime Error

Doubts

Problems

Topic: Exception Handling Syntax In Java Programming

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App