File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "exceptions" Watch "exceptions" New topic


Jui Mahajan
Ranch Hand

Joined: Jun 02, 2003
Posts: 62
Consider the following code. What actually happens to the return statement in the catch clause ? If the catch block had been executed, there would then be two return statements. So is that not an error ? Pls help..
public class Ppvg{
public static void main(String argv[]){
Ppvg p = new Ppvg();
public int fliton(){
FileInputStream din = new FileInputStream("");;
}catch(IOException ioe){
return 99;
return -1;

-----jui<br />scjp1.4
Hanna Habashy
Ranch Hand

Joined: Aug 20, 2003
Posts: 532
only one return statement will be excuted. look at the code carefully. If an exception is thrown, and catch block is excuted, it returns (99) and end the method - after the finally block. However, if the catch block is not excuted, then the last return statemt (-1) will be reached and return the method.
if you ommit the last return statment, the code will not compile

SCJD 1.4<br />SCJP 1.4<br />-----------------------------------<br />"With regard to excellence, it is not enough to know, but we must try to have and use it.<br />" Aristotle
I agree. Here's the link:
subject: exceptions
It's not a secret anymore!