Menu
Question Index
...

What will be the output of the following program?

public class GetExceptions {
    public static void main(String[] args) {
        try {
            throwException();
        } catch (Exception e) {
            System.out.println("Exception Handled in Main");
        }
        doesNotThrowException();
    }
    public static void throwException() throws Exception {
        try {
            System.out.println("Method throwException");
            throw new Exception();
        } catch (Exception e) {
            System.out.println("Handled in method throwException");
            throw e;
        } finally {    System.out.println("Finally is Always Exceuted ");    }
    }
    public static void doesNotThrowException() {
        try {    System.out.println("method doesNotThrowException");    }
        catch (Exception e) {    System.out.println(e.toString());    }
        finally {    System.out.print("Finally is always Executed.");    }
    }
}


Method throwException
Handled in method throwException
Finally is Always Exceuted
Exception Handled in Main
method doesNotThrowException
Finally is always Executed.
method doesNotThrowException
Finally is always Executed.
Handled in method throwException
Finally is Always Exceuted
method doesNotThrowException
Finally is always Executed.
Exception Handled in Main
Finally is Always Exceuted
method doesNotThrowException
Finally is always Executed.
Output cannot be determined
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java Throw Keyword - Java Throws Keyword

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App