Timeline for In Java, what are checked exceptions good for?
Current License: CC BY-SA 3.0
7 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jul 9, 2014 at 20:59 | comment | added | supercat | @owlstead: Checked exceptions should only bubble through intermediate layers of the call stack if they are thrown in cases that the intermediate calling code expects. IMHO, checked exceptions would have been a good thing if callers had to either catch them or indicate whether or not they were expected; unexpected exceptions should be automatically wrapped in an UnexpectedException type derived from RuntimeException. Note that "throws" and "doesn't expect" are not contradictory; if foo throws BozException and calls bar, that doesn't mean it expects bar to throw BozException. | |
| Jun 2, 2014 at 9:47 | comment | added | Thomas W | Checked exceptions were intended for contingencies -- predictable & recoverable outcomes other than success, as distinct from failures -- unpredictable low-level/ or system problems. FileNotFound or error opening a JDBC connection were both correctly considered contingencies. Unfortunately, Java library designers made a total mistake & assigned all other IO and SQL exceptions to the 'checked' class also; despite these being almost completely unrecoverable. literatejava.com/exceptions/… | |
| Apr 26, 2014 at 17:30 | comment | added | Jerry Coffin | @owlstead: Thanks--I probably should have been more careful with the wording there. The point wasn't so much that you actually had to catch the exception as it was that every intermediate level of code needs to be aware of every exception that might flow through it. As for the rest: having a tool that makes it quick and easy to make a mess of your code doesn't change the fact that it's making a mess of the code. | |
| Apr 26, 2014 at 17:25 | history | edited | Jerry Coffin | CC BY-SA 3.0 | added 10 characters in body |
| Apr 26, 2014 at 17:18 | history | edited | Jerry Coffin | CC BY-SA 3.0 | added 4 characters in body |
| Apr 26, 2014 at 10:32 | comment | added | Maarten Bodewes | Your very first initial statement about having to handle the exception directly is already false; you can simply add a throws statement, and that throws statement may be of a parent type. Furthermore, if you really don't think you have to handle it you can simply convert it to a RuntimeException instead. IDE's commonly help you with both tasks. | |
| Nov 16, 2010 at 4:33 | history | answered | Jerry Coffin | CC BY-SA 2.5 |