aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Is the sequence of output correct? 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 "Is the sequence of output correct?" Watch "Is the sequence of output correct?" New topic
Author

Is the sequence of output correct?

Balaguru Janarthanan
Ranch Hand

Joined: Nov 01, 2000
Posts: 37
import java.io.*;
public class Mine {
public static void main(String argv[]){
Mine m=new Mine();
System.out.println(m.amethod());
}
public int amethod() {
try {
FileInputStream dis=new FileInputStream("Hello.txt");
}
catch (FileNotFoundException fne) {
System.out.println("No such file found");
return -1;
}
catch(IOException ioe) {
}
finally{
System.out.println("Doing finally");
}
return 0;
}
}
prints: Nosuchfilefound, doing finally, -1.
is it not like this: Nosuchfilefound,-1,doingfinally.
pls help.
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Balaguru,
Yes the output order is correct. The finally part of a try block will always be executed before completing the block. The only way to avoid executing a finally block would be to call System.exit() method from within the try or catch blocks.
Manfred.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Is the sequence of output correct?