I don't know about the Eclipse but, I went through the same problem, and one thing that I saw here during my searches for the answer, is that, in some cases, you have to throw an Exception in your method, or put a try/catch around your if/else, and here is the reason (taken from StackOverflow
"Unchecked exceptions are those that extend RuntimeException class. Compiler will never force you to catch such exception or force you to declare it in the method using throws keyword. All other exception types (that do not extend RuntimeException) are checked and therefore must be declared to be thrown and/or catched."
The rule of thumb here is:
for any exception (except RuntimeException), you must consider the usage of "throws Exception" or "try/catch". It depends on you.
Without a "try/catch" or "throw Exception", this could happen at Eclipse, for example:
"Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Unhandled exception type IOException
Considering that the possible exception that can occur from trying to create a file is "IOException", the rule above applies to this scenario
Here is a code which I used "throw Excepetion":