Re:RuntimeExceptions – To try-catch or not to catch?
by smoyer on Saturday March 09, 2013 @04:34PM
(#5349705)
I'd love to be able to say I never have to catch RuntimeExceptions, but that would require that library and framework writers actually use checked exceptions when they should. The best example I can think of (and one that a JEE developer who uses JPA should be intimately familiar with) is that that the getSingleResult() method of the Query object in JPA throws RuntimeExceptions if zero or more than one result is returned.
[ Parent
| on HN ]
Re:RuntimeExceptions – To try-catch or not to catch?
by suresk on Saturday March 09, 2013 @04:48PM
(#5349742)
The funny thing is, in almost any discussion about exception handling in Java, I hear the opposite complaint - too many APIs throw checked exceptions. I've been leaning more and more to liking it when APIs force consumers to at least be aware of known error conditions.
Scala's Option type is another example of this - I've watched people be sort of annoyed by it at first, but it tends to really improve the reliability and overall quality of the code when it is used properly.
Re:RuntimeExceptions – To try-catch or not to catch?
by lucian1900 on Saturday March 09, 2013 @05:17PM
(#5349815)
Scala's Option is a monad, so it's very easy to chain several actions and safely decide if they all succeeded or failed. It doesn't compare with checked exceptions at all.