• 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
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • 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 ]
 
Try 100 things. 2 will work out, but you will never know in advance which 2. This tiny ad might be one:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic