This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Mock Question Doubt...EQ+...Loops, Iterators and Exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Mock Question Doubt...EQ+...Loops, Iterators and Exceptions" Watch "Mock Question Doubt...EQ+...Loops, Iterators and Exceptions" New topic
Author

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

Hardik Raja
Ranch Hand

Joined: Feb 07, 2006
Posts: 117
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

Joined: Feb 28, 2007
Posts: 1707
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 ]

cmbhatt
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mock Question Doubt...EQ+...Loops, Iterators and Exceptions
 
Similar Threads
Couple of questions
no ArithmeticException??
Exception vs return
Exception
Checked exception and interface.