The constructor Formatter(String fileName) doesn't seem to compile when I don't handle FileNotFoundException even if the file already exists.
Here's the code that works:
import java.util.*;
public class CreatingFiles {
public static void main(String[] args) {
final Formatter MYFILE;
try {
MYFILE = new Formatter("john.txt");
System.out.println("File created");
}
catch (Exception e) {
System.out.println("Error!");
}
}
}
However when I remove the try/catch block:
import java.util.*;
public class CreatingFiles {
public static void main(String[] args) {
final Formatter MYFILE;
MYFILE = new Formatter("john.txt");
}
}
The compiler tells me that I have to either throw or catch the exception. So why doesn't it work without handling the exception?