File size: 552 Bytes
c574d3a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import java.io.FileNotFoundException;
import java.io.PrintWriter;
public class CheckedExceptionExample {
public static void main(String[] args) {
PrintWriter pw = null;
try {
pw = new PrintWriter("jtp.txt"); // may throw exception
pw.println("saved");
}
// providing the checked exception handler
catch (FileNotFoundException e) {
System.out.println(e);
} finally {
pw.close();
}
System.out.println("File saved successfully");
}
}
|