I\'m reviewing a midterm I did in preparation for my final exam tomorrow morning. I got this question wrong, but there\'s no correct answer pointed out, and I neglected to a
Although an answer has already been chosen for this question, I think that the correct answer to your test is number 3:
- The main method should simply terminate if the FileNotFoundException occurs.
Because it says should, not would.
I mean, the code in the method can catch any exception, both checked and unchecked, and either, swallow, recover from or rethrow it — or it could not catch them at all.
But if it catches a FileNotFoundException without ultimately (re)throwing it, it is breaking its own contract: any caller won't see the exception as stated in the method signature, because the method handled it (maybe even the compiler could complain in that case, saying that the exception is never thrown, but I not sure here).
I think your midterm was posing a question about design rather than about a specific implementation.