Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
arivu mathi
Ranch Hand
Posts: 38
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 39
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 208
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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 ]
 
ram gaurav
Ranch Hand
Posts: 208
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic