Menu
Question Index
...

What will be the output of the following program?

public class Valid {
    public static void main(String[] args) {
        try {
            throwException();
        } catch (Exception e) {
            System.out.println("Exception Handled in Main");
        }
        doesNotThrowException();
    }
    
    public static void throwException() {
        try {
            System.out.println("Method throwException");
            int k = 56 / 0;
        } catch (Exception e) {
            System.out.println("Handled in method throwException");
        }
    }
    public static void doesNotThrowException() {
        try {
            System.out.println("method doesNotThrowException");
        } catch (Exception e) {
            System.out.println(e.toString());
        }
    }
}


Method throwException
Handled in method throwException
Method throwException
Handled in method throwException
method doesNotThrowException

Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: Try Catch Block In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App