3 ms·
Checked exceptions are evil because they can cause transitive API breakage in cases a function or method doesn’t catch because it can’t or shouldn’t handle the
by baq 6y ago
Checked exceptions are evil because they can cause transitive API breakage in cases a function or method doesn’t catch because it can’t or shouldn’t handle the condition.
- kibwen 6y agoSince this thread is also about Rust, and since I mention in another comment about how Rust libraries define their own error types, I should mention that Rust can avoid this problem by the combination of 1) adding a new way that a function can error only requires adding a new case to the library's error enum, leaving the function's type signature unchanged, 2) adding new cases to the error enum can be kept from being a breaking change via the use of the non_exhaustive attribute, which requires anyone manually handling the error to add a default case even if they handle all the other existing cases. Of course, if library consumers are just throwing a panic in that mandatory default case then you might be trading a compiler error for a runtime error, which can be controversial. The language design challenge of this decade is finding compromises between allowing libraries to change and evolve while mitigating the disruptiveness to downstream consumers.
- flowerlad 6y agoSorry that doesn't make any sense to me. If a method can't or shouldn't hand a condition it then it needs to declare itself as throwing that exception (or a wrapper around it).
- withinboredom 6y agoThey said transitive. To me, they meant if you have 3 layers of deps, A -> B -> C and C now throws something, B doesn’t catch it or mark as throws. So now you have a failure. Obvs, you’d fix this immediately, but it’s still work that you have to do when you could have been doing something productive.
- ddek 6y agoHere's Hejlsberg on why C# doesn't have checked exceptions: https://www.artima.com/intv/handcuffs.html https://www.artima.com/intv/handcuffs.html.
- flowerlad 6y agoHejlsberg is an awesome compiler maker. His Turbo Pascal compiler was incredible -- in approx 30KB he wrote a compiler, full screen editor and library. He's not that good as a language designer. C# is basically a clone of Java with broken exception handling. Here's the problem with C# exceptions: https://web.archive.org/web/20041201011903/http://www.geocities.com/csharpfaq/exceptions.html https://web.archive.org/web/20041201011903/http://www.geocit...