when to throw FileNotFoundException

Java has some controversy about its exceptions. It has two classes of exceptions. Checked and unchecked. Any exception extending from RuntimeException or Error is unchecked and does not need to be caught or explicitly declared as throwable in a method signature.

FileNotFound is however a checked exception and must either be caught or declared as throwable in the method signature.

The basic idea is that checked exceptions are ones that you may be able to recover from while unchecked exceptions are ones coming from a most likely unrecoverable error in programming.

You can read all about it here: https://docs.oracle.com/javase/tutorial/essential/exceptions/runtime.html

Leave a Comment