Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Hardik Raja
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
  • 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..??

 
Chandra Bhatt
Ranch Hand
Posts: 1710
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic