4 ms·
There is nothing failed about checked exception. It is better then finding out about runtime exceptions as they happen.
by watwut 7y ago
There is nothing failed about checked exception. It is better then finding out about runtime exceptions as they happen.
- nine_k 7y agoIf an exception should be expected and handled, it's not an exceptional case, it's a part of the function's signature. The lack of sum types and pattern matching notwithstanding, such a signature can be implemented reasonably in Java.
- chopin 7y agoI am not against checked exceptions per se. Their excessive use of them in the standard library and especially the inability of lambdas in handling them are a problem imho. Take the stream close methods: There is absolutely no use in having those throwing a checked exception because there is nothing you can do. If closing is not possible you have problems with the underlying OS. That would rather warrant an error instead of an exception.
- Quekid5 7y agoYes there is. I have enough material enough on this for several blog posts, but I won't belabor the point. One, why do you think almost all non-standard java libraries almost exclusively use exceptions derived from RuntimeException? Two, I encourage you to look up guava's Throwables utility class and consider why it is even a thing. Just for a single example: Methods with no throws clause cannot throw exceptions, so you must wrap in a RuntimeException... but that means that outer catch clauses which match on the checked exception WILL NOT MATCH on the RTExc-wrapped-exception. This is broken as all hell.