4 ms·
Exactly. I think the 2 key failings of the checked exception idea (there are others, but not as important) are 1) Precise exception specifications leak impleme
by paol 14y ago
Exactly. I think the 2 key failings of the checked exception idea (there are others, but not as important) are
1) Precise exception specifications leak implementation details. This will bite you badly, e.g., when you want to change the implementation from under a published API.
2) The times when we only care that some exception occurred vastly outnumber the times when we care about the exact types of exceptions that may occur. Checked exceptions don't add any value to the common case, in fact they make it worse, because generic exception handlers tend to live many levels up the call stack from where exceptions are thrown(1), and therefore they "aggregate" large amounts of code that that can collectively throw a huge range of exceptions. If you were to carry around detailed "throws" clauses, they would be a mile long.
The funny thing is, all solutions that solve the problems created by checked exceptions do so by subverting the mechanism one way or another. So you're better off without checked exceptions in the first place.
I've always been interested in this discussion because it's one of those cases where an idea seems very good on paper, only to turn out quite bad in practice.
(1) This observation is what makes exceptions such a useful mechanism in the first place.
- bunderbunder 14y agoThere is one part of the idea that I'd like to salvage, though, and that's having some clear documentation right there in the code about what kinds of exceptions I can expect to see a procedure throw. At the very least it'd be useful for when I'm wearing my "DLL author" hat, since it'd give me an easy way to look through the public interface and make sure exceptions won't be causing unrighteous leakage of implementation details for the end-user. I'd rather not put users in a situation where they have to look at the framework source in order to interpret an exception. It's kind of irritating when that happens. I think it's really not something that should require special language statements, though. A static analyzer should be able to automatically figure it out.