4 ms·
> FileNotFoundException is something my code can probably recover from - you asked for a file Actually, no. Sometimes it is fatal, and sometimes it's not. If
by hota_mazi 6y ago
> FileNotFoundException is something my code can probably recover from - you asked for a file
Actually, no. Sometimes it is fatal, and sometimes it's not.
If the file being open is expected to be part of the distribution and your app can't start without it, it's fatal.
If it's a file picked by the user, it's most likely recoverable.
The main problem is that every single one of these exceptions should be able to be either runtime or checked, and that choice should be made by the application.
Open question: should this decision be made at the call site or the use site?
- jimbobimbo 6y agoCall site vs use site is a great dichotomy for this discussion. My position is that the caller decides how to deal with exceptions. When I'm adding a new operation to my web app, I won't add any exception handling at all. Why would I? There's a central exception handler in my app, which will log exception, analyze its type and return an appropriate status code to the caller (e.g. 500 or 400). If there's a kind of failure my centralized handler doesn't handle correctly, I'll add an explicit handler in the new operation, which would do the right thing in some cases, while the rest of issues are handled centrally still. Checked exceptions make me have dummy handlers all over the place.