Topics Index

Program with try catch blocks

If you need explanation Read this topic

If you need Answer Take test on this topic

Program with try catch blocks
What will be the output of the following program?

public class Exception4
    void m() throws IOException {
        throw new"device error");
    void n() {
    void p() {
        try {
        } catch (Exception e) {
            System.out.println("exception handled");
    public static void main(String args[]) {
        Exception4 obj = new Exception4();
        System.out.println("normal flow");

A. exception handled
normal flow
B. device error
exception handled
normal flow
C. device error
normal flow
D. Compilation Error or Runtime Error
Topic: Java Throw Keyword - Java Throws Keyword

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans:B exception will be thrown at m() it displays "device error" will be caught at p() displays "exception handled" and finally termination by displaying "norma flow"

Posted by Indrasena Reddy    2014-06-17 09:25:38

answer is A as we are calling P() method which in turn call n() and N() call m() which throws an IOExeception which is handled by catch in p() method and then "normal flow" will be printed

Posted by Ashok Kumar Paritala    2014-06-17 09:27:00

Ans is d..m() throwing exception but we are not handling from calling side in n()

Posted by Uday Kumar    2014-06-17 09:27:13

ans d..p() method cals n().
n() cals m() and this methd needs exception handling so it throws IOexcption unhandld type

Posted by Maheshwari Natarajan    2014-06-17 09:37:17

answer is d...becoz m is thowng the xception eithnr n shud catch or throw it but it is nt doing so

Posted by Vijay Kumar    2014-06-17 09:45:11

Congratulations Maheshwari Natarajan. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-06-18 04:08:34

© meritcampus 2019

All Rights Reserved.

Open In App