Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Mock Question Doubt...EQ+...Loops, Iterators and Exceptions

 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question ID : com.enthuware.ets.scjp.v5.2.200



The above code compiles prefectly without any error...

My question is the below method says it returns int, and it doesn't return anything......how does this pass the compiler..??

 
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you make a return statement there, the compiler complains that the
code is not reachable. Code below the throw statement is not reachable.
There is no error irrespective that the method says that it returns int,
because the code throws the exception explicitly using "throw".


If there is something like
int a=10;
int b=a/0;
then you must return the int from the method because there is exception (divide by zero) that is not known until the line b=a/0 is executed at run time.



Thanks,
[ May 31, 2007: Message edited by: Chandra Bhatt ]
 
Those cherries would go best on cherry cheesecake. Don't put those cherries on this tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic