5.5) Will a finally block execute even if the catch block defines a return statement?


Example:
import java.io.FileInputStream;
import java.io.FileNotFoundException;
public class ReturnFromCatchBlock {
public static void main(String[] args) {
openFile();
}
private static void openFile() {
FileInputStream fis = null;
try {
fis = new FileInputStream("file.txt");
} catch (FileNotFoundException fnfe) {
System.out.println("file not found");
return;
} finally {
System.out.println("finally");
}
System.out.println("Next task..");
}
}



Previous5.4) Using a method that throws an errorNext5.6) What happens if both a catch and a finally block define return statement?
Last updated
Was this helpful?