• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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......
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic