Gerard said:
- Versioning: though true, this holds for more properties of the
signature (so, not a strong argument)
I think it's a tradeoff. In the time of the Java boom I didn't like checked
exceptions because they made everything more complicated without adding more
value. What other properties of a signature add less value than checked
properties would do?
In addition, checked exceptions would not increase code quality, simply
because the avarage programmer would catch it instead of propagating it
using 'throws...' in the procedure's head, and, to make it even worse,
assign an empty exception handler. Checked exceptions always were a
controversial feature in the Java community and subject of discussion.
You'll find many articles on the web discussing checked exceptions and if
they are valuable enough to be added to a programming language. An
interesting article by Bruce Eckel (who authored books about Java) can be
found here:
Does Java need Checked Exceptions?
<URL:
http://www.mindview.net/Etc/Discussions/CheckedExceptions>
The last comment on the page referenced above quotes Eric Gunnerson
(<URL:
http://discuss.develop.com/archives/wa.exe?A2=ind0011A&L=DOTNET&P=R32820>),
who was one of the designers of C#:
| Examination of small programs leads to the conclusion
| that requiring exception specifications could both enhance
| developer productivity and enhance code quality, but experience
| with large software projects suggests a different result --
| decreased productivity and little or no increase in code quality.
Time has shown that checked exceptions were a bad idea, and thus they were
not included. There was for sure a long process of discussion going on
before this decision.
- Code quality: if A calls B, B calls C, C calls D, and D raises
an exception that is eventually handled by A, A normally doesn't know
anything about the context of the exception and hence can't handle
"program state" properly.
In this case, handle the exception in 'C'. My daily developer experience
shows me that I always keep the documentation opened to lookup the
exceptions thrown by methods I use in my code. I think there are more
evolved concepts to increase code quality than checked exceptions. Checking
for empty exception handlers (using tools like FxCop), using automated tests
(unit testing) and better training are far more effective without affecting
versioning, for example.
- If the number of possible exceptions could be large, so make
checked exceptions optional.
That's what Java does, IIRC.