*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes will the code give cmpiler error...... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "will the code give cmpiler error......" Watch "will the code give cmpiler error......" New topic
Author

will the code give cmpiler error......

arivu mathi
Ranch Hand

Joined: Jun 26, 2006
Posts: 38
public class Test3{
public static void main(String args[]){
System.out.println(method());
}
public static int method(){
try{
throw new Exception();
}
catch(Exception e){
throw new Exception();
}
finally{
return 3;
}
}
}

in one of the mock exam tha answer s compiler error...but it's working fine.....can u plz explain this......
Finner Jones
Ranch Hand

Joined: Jun 12, 2006
Posts: 39
Hi,
It compiles and runs for as well. It looks like the mock has a mistake �?
What mock is it ?

Finner
ram gaurav
Ranch Hand

Joined: Mar 29, 2006
Posts: 208
No , it is not complier error.
But i am not able to understand that like we are throwing the Exception explicitly but on runtime it is not giving any error , it is working fine that is , it is printing 3 as output.
Could you tell me why.

Thanks
Regards
Gaurav
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729


Yes it compiles and produces the output 3.
Where did this question come from? Exactly what Mock Exam?
Please use tags around your code in future.
[ June 30, 2006: Message edited by: Barry Gaunt ]

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
ram gaurav
Ranch Hand

Joined: Mar 29, 2006
Posts: 208
No , it is not complier error.
But i am not able to understand that like we are throwing the Exception explicitly but on runtime it is not giving any error , it is working fine that is , it is printing 3 as output.
Could you tell me why.

Thanks
Regards
Gaurav
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Read JLS 14.20.2. It seems that return 3 is considered an abrupt ending of the finally block so that the second thrown Eception is lost.
 
 
subject: will the code give cmpiler error......
 
Similar Threads
Exception
somebody pls explain why this code does not give an exception
Exception
Exception test
one doubt