What is the output of this program #1?

2 views
Skip to first unread message

Rohit Ghatol

unread,
Dec 6, 2007, 10:04:30 AM12/6/07
to Pune Java Interview Questions Group
try{
....
}
catch(Exception e){
......
}
catch(AException e){
......
}


Try to guess instead of running the code. Think what the java compiler
guy was thinking when they wrote java specs.

Pratham

unread,
Feb 1, 2008, 6:13:51 AM2/1/08
to Pune Java Puzzles
If at all in this code an exception is thrown is going to get caught
in the first catch block and it will skip all other catches.

The idea is to catch the more specific exception rather than then
catching the more generic one. and if at all we do not have the catch
block for the specific exception then only it should throw the generic
exception

Yogesh Patel

unread,
Feb 4, 2008, 5:32:03 AM2/4/08
to pune-jav...@googlegroups.com
So , java compiler report error for that, its unreachable code.
Reply all
Reply to author
Forward
0 new messages