Re: Checked Exceptions!
"Jon Skeet" <skeet@pobox.co m> wrote in message
news:MPG.199983 89ee23e0c398a27 3@news.microsof t.com...[color=blue]
> Frans Bouma <perseus.news@x s4all.nl> wrote:[color=green][color=darkred]
> > > Basically an implementation/override can declare that it throws fewer
> > > exceptions, but not more.[/color]
> >
> > Ok, but doesn't an interface implicate a fixed definition? So if an
> > implementator decides not to throw a given exception, does that
> > implementator in fact not implement the complete interface? It looks[/color][/color]
like[color=blue][color=green]
> > Sun cut a corner on this :)[/color]
>
> No, not at all. The interface says what you should do if a certain type
> of thing does wrong. If that kind of thing can't possibly go wrong in
> your implementation, then there's no need to redeclare that.
>
> It's basically the Liskov Substitutabilit y Principle again - the
> interface says, "If you've got something that implements this
> interface, you can call this method and expect a certain result if a
> certain thing goes wrong" - and the implementation where that certain
> thing can't go wrong is still abiding by that interface.
>
> --[/color]
This approach should work but it begs the question of whether an exception
specification in an interface is a useful feature to have. I am not
convinced that adding it to an interface definition yields the expected
benefits because a real-world implementation may have many more exception
types to deal with then the designer of the interface ever expected.
I see the value in some flavor of checked exceptions as a design-time aid
rather then a runtime requirement.
There is a benefit for tools to be capable to tracing the exception graph of
an object. At design time when using a given type I am concerned about what
it might do so that I can write code to correctly handle the exception. I
want the exception information to be available to me (through intellisense)
for the same reason I want to know the arguments to a method. I think this
would work well when dealing with concrete types; it works less well with
late-bound types where the actual type or instance is not known until
runtime, as typically occurs when using reflection against a type or an
interface.
I'd rather not have any information then have incorrect information and
relying on interface specifications creates the problem of the documentation
not matching the code. I think the feature is most useful when the language
compiler can automatically generate the information at the time the type or
interface is compiled into IL. I believe it less useful to rely on interface
declarations as this can get out-of-date and be mismatched very easily - the
number of ways to get this wrong is larger then the number of ways to get it
right. It's easy to do on small projects, but on large projects (where the
feature adds the most benefits) it's harder to maintain.
Computers are good at automating repetitive tasks; detecting exceptions that
can be thrown from a given implementation falls into this category.
Note to designers of future languages - the existence of this debate is a
clue that this aspect of programming needs a lot of thought. I have yet to
see a language and runtime implementation that solves the general error
handling problem correctly and consistently. We've come a long way from the
"System error 42" days but there's a lot more work that needs to be done.
Dave
"Jon Skeet" <skeet@pobox.co m> wrote in message
news:MPG.199983 89ee23e0c398a27 3@news.microsof t.com...[color=blue]
> Frans Bouma <perseus.news@x s4all.nl> wrote:[color=green][color=darkred]
> > > Basically an implementation/override can declare that it throws fewer
> > > exceptions, but not more.[/color]
> >
> > Ok, but doesn't an interface implicate a fixed definition? So if an
> > implementator decides not to throw a given exception, does that
> > implementator in fact not implement the complete interface? It looks[/color][/color]
like[color=blue][color=green]
> > Sun cut a corner on this :)[/color]
>
> No, not at all. The interface says what you should do if a certain type
> of thing does wrong. If that kind of thing can't possibly go wrong in
> your implementation, then there's no need to redeclare that.
>
> It's basically the Liskov Substitutabilit y Principle again - the
> interface says, "If you've got something that implements this
> interface, you can call this method and expect a certain result if a
> certain thing goes wrong" - and the implementation where that certain
> thing can't go wrong is still abiding by that interface.
>
> --[/color]
This approach should work but it begs the question of whether an exception
specification in an interface is a useful feature to have. I am not
convinced that adding it to an interface definition yields the expected
benefits because a real-world implementation may have many more exception
types to deal with then the designer of the interface ever expected.
I see the value in some flavor of checked exceptions as a design-time aid
rather then a runtime requirement.
There is a benefit for tools to be capable to tracing the exception graph of
an object. At design time when using a given type I am concerned about what
it might do so that I can write code to correctly handle the exception. I
want the exception information to be available to me (through intellisense)
for the same reason I want to know the arguments to a method. I think this
would work well when dealing with concrete types; it works less well with
late-bound types where the actual type or instance is not known until
runtime, as typically occurs when using reflection against a type or an
interface.
I'd rather not have any information then have incorrect information and
relying on interface specifications creates the problem of the documentation
not matching the code. I think the feature is most useful when the language
compiler can automatically generate the information at the time the type or
interface is compiled into IL. I believe it less useful to rely on interface
declarations as this can get out-of-date and be mismatched very easily - the
number of ways to get this wrong is larger then the number of ways to get it
right. It's easy to do on small projects, but on large projects (where the
feature adds the most benefits) it's harder to maintain.
Computers are good at automating repetitive tasks; detecting exceptions that
can be thrown from a given implementation falls into this category.
Note to designers of future languages - the existence of this debate is a
clue that this aspect of programming needs a lot of thought. I have yet to
see a language and runtime implementation that solves the general error
handling problem correctly and consistently. We've come a long way from the
"System error 42" days but there's a lot more work that needs to be done.
Dave
Comment