Re: Checked Exceptions!
Frans Bouma <perseus.news@x s4all.nl> wrote in
news:Xns93CE678 A35CCCperseusne wsxs4allnl@207. 46.248.16:
[color=blue]
> So are the pro-checked exception reasons!
> If documentation about which exceptions a method can throw is not
> enough, what is?
> different implementations which can throw different exceptions,
> however when you define them as checked in the interface, you are not
> able to do that.[/color]
Far from being an issue of sloppiness, the absence of checked exceptions
presents a very real limitation to the design of well-encapsulated
components. Documentation is important, of course; nobody's questioning
that. However, if documentation were enough, then return- and parameter-
checking would be extraneous as well. You will probably argue that
exceptions are different because they are more closely related to the
implementation. However, that's the crux of the problem: interfaces are
supposed to prevent implementation details from being exposed.
But just as you're not limited to returning the exact type specified in
a method signature, you aren't being crippled by checked exceptions.
Make no mistake about it. As long as any inner exception is a subclass
of or wrapped in an instance of the throwable types that are permitted
by the interface, nothing prevents you from passing back any extended
data specific to the implementation at hand.
In fact, checked exceptions offer a safer way to throw your own
exceptions, because you'll know that doing so won't break the calling
code if it's not expecting your particular exception's runtime type.
That's what it all boils down to: by replacing the underlying
implementation without making any guarantees on the type of data to
expect, you aren't running the risk of an unexpected exception bubbling
up clear off the stack or of needing to rewrite code everywhere, as is
currently the case with .NET.
Finally, if you're still not convinced, remember that you'd be free to
automagically add "throws Exception" to all your methods and resume your
work hassle-free. =)
Frans Bouma <perseus.news@x s4all.nl> wrote in
news:Xns93CE678 A35CCCperseusne wsxs4allnl@207. 46.248.16:
[color=blue]
> So are the pro-checked exception reasons!
> If documentation about which exceptions a method can throw is not
> enough, what is?
> different implementations which can throw different exceptions,
> however when you define them as checked in the interface, you are not
> able to do that.[/color]
Far from being an issue of sloppiness, the absence of checked exceptions
presents a very real limitation to the design of well-encapsulated
components. Documentation is important, of course; nobody's questioning
that. However, if documentation were enough, then return- and parameter-
checking would be extraneous as well. You will probably argue that
exceptions are different because they are more closely related to the
implementation. However, that's the crux of the problem: interfaces are
supposed to prevent implementation details from being exposed.
But just as you're not limited to returning the exact type specified in
a method signature, you aren't being crippled by checked exceptions.
Make no mistake about it. As long as any inner exception is a subclass
of or wrapped in an instance of the throwable types that are permitted
by the interface, nothing prevents you from passing back any extended
data specific to the implementation at hand.
In fact, checked exceptions offer a safer way to throw your own
exceptions, because you'll know that doing so won't break the calling
code if it's not expecting your particular exception's runtime type.
That's what it all boils down to: by replacing the underlying
implementation without making any guarantees on the type of data to
expect, you aren't running the risk of an unexpected exception bubbling
up clear off the stack or of needing to rewrite code everywhere, as is
currently the case with .NET.
Finally, if you're still not convinced, remember that you'd be free to
automagically add "throws Exception" to all your methods and resume your
work hassle-free. =)
Comment