Topics Index

Identify lines of code executed471

If you need explanation Read this topic

If you need Answer Take test on this topic

Identify lines of code executed471
What lines of the following program gets executed, given that the exception is thrown at LINE B.
    // LINE A
        // LINE B
    catch(Exception ex)
        // LINE C
    // LINE D
catch(Exception e)
    // LINE E
    // LINE F

A. A, B, C, D, E, F, G
B. A, B, C, E, F, G
C. A, B, D, E, F, G
D. A, B, C, D, G
Topic: Try Catch Block In Java

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.

Answer is A...Here all the lines will be executed because when an exception occurs only those lines that are next to the one where exception occured does not execute

Posted by Shashanka Mogaliraju    2014-11-18 12:37:53


Posted by Dereje Goshu    2014-11-18 12:39:16

Ans is we have the concept of the inner try catach mechanisam..which means we can have try-catch block inside the try or catch if the Exception is thrown inner try than it will check in catch if its not handling than it will check for the Outer catch...if the Exception is thrown at outer try than it will check firectly in outer cahtch only....

here if the Exception is thrown at Line b means it will Execute A,B

here Line B means Exception is thrown at inner try than it will check in inner we are receving through the Exception which is Parent class for all Exceptions so that it wil Handled here so that Line C also get executed...

Next Exception is handled so that No Problem with outer catch so that line D also Get executed....

next here we didnt get any exception so that  no need to go for outer catch,,,and inner try Excpetion is alsp handled by inner catch only than no need to go fot Outer catch,...

next here we have line G which is independent to the try that it will execute automatically

Posted by Uday Kumar    2014-11-18 12:40:19

ans is D,, due to exception at B line C execute by its catch box,, line E,F not execute ,,they r in outer catch box ,,,

Posted by Raju VarshnEy    2014-11-18 12:42:36

ans id d bcz
first line A executes, the first statement in try then line B executes which is in nested try then an exception occurs at lineB so caught in immediate catch block so lineC is excuted  then after the catch block lineD executes then lineG. The second catch block will not execute because exception related to that is not thrown So ans id D

Posted by Pooja Singh    2014-11-18 12:45:13

ans d.                                                                                                                                 try block within a try block is known as nested try block.Sometimes a situation may arise where a part of a block may cause one error and the entire block itself may cause another error. In such cases, exception handlers have to be nested.                                                                                                      try catch mechanism mainly used to handle run time exception.                                                      in this program from the given statement line A get executed successfuly so no exception thrown,if line A throws erros thn directly outer catch block get executed.                                                                                                                         from givn statement line B throws exception so this exception catchd by following inner catch line c execption handled by inner catch block ,aft this line D get executed.outer catch block not get executed so E,Flines not get executd.aft this control goes ouside of the try catch block finally line G get executed

Posted by Maheshwari Natarajan    2014-11-18 15:48:10

answer b . nested try block is used in this program. here line A get executed thn line B throws error so here catch block get executed so line C executed. but here if the catch block unable to handle the exception thn exception rethrown to the outer block .so here line D not executed.outer catch block E,F lines get executed. thn control goes outside of trycatch block thn line G get executed

Posted by NagaRaj Nataraj    2014-11-18 19:39:23

This dose is now closed and the winners are Uday Kumar,  for 'First Correct Comment', Pooja Singh, Maheshwari Natarajan,  for 'Best Comment' and Sai Ram for the 'Popular Comment'. The 'lucky liker' is Uday Kumar. Please login into Merit Campus using facebook, to claim your recharge. Go to to raise the recharge.

Posted by Merit Campus    2014-11-19 01:52:01

© meritcampus 2019

All Rights Reserved.

Open In App