Program logic bugs vs input/environmental errors

Jeremy Powers via Digitalmars-d digitalmars-d at puremagic.com
Tue Sep 30 12:18:00 PDT 2014


On Tue, Sep 30, 2014 at 5:43 AM, Steven Schveighoffer via Digitalmars-d <
digitalmars-d at puremagic.com> wrote:

> ...
> Well, the failure comes from the effort to effect a certain behavior.
>
> Sun was looking to make programmers more diligent about handling errors.
> However, humans are lazy worthless creatures. What ends up happening is,
> the compiler complains they aren't handling an exception. They can't see
> any reason why the exception would occur, so they simply catch and ignore
> it to shut the compiler up.
>
> In 90% of cases, they are right -- the exception will not occur. But
> because they have been "trained" to simply discard exceptions, it ends up
> defeating the purpose for the 10% of the time that they are wrong.
>
>
That's the argument, but it doesn't seem valid to me.  Without checked
exceptions, you will always be ignoring exceptions.  With checked
exceptions, you have to explicitly ignore (some) exceptions, and when you
do it is immediately obvious in the code.  You go from everyone ignoring
exceptions all the time, to some people ignoring them - and being able to
easily notice and call out such.

Anyone 'trained' to ignore checked exceptions are simply shooting
themselves in the foot - same as if there were no checked exceptions, but
with more verbosity.  This is not a failure of checked exceptions, but a
failure of people to use a language feature properly. (Which, yeah, meta is
a failure of the feature... not going to go there)



> If you have been able to resist that temptation and handle every
> exception, then I think you are in the minority. But I have no evidence to
> back this up, it's just a belief.
>
>
In my world of professional java, ignoring exceptions is an immediate,
obvious indicator of bad code.  You will be called on it, and chastised
appropriately.  So from my standpoint, Sun was successful in making
programmers more diligent about handling errors.



>  Note I am not advocating adding checked exceptions to D (though I would
>> like it).  Point is to acknowledge that there are different kinds of
>> exceptions, and an exception for one part of the code may not be a
>> problem for the bit that invokes it.
>>
>>
> I think this is appropriate for a lint tool for those out there like
> yourself who want that information. But requiring checked exceptions is I
> think a futile attempt to outlaw natural human behavior.
>
>
Perhaps I shouldn't have mentioned checked exceptions at all, seem to be
distracting from what I wanted to say.  The important bit I wanted to bring
to the discussion is that not all exceptions are the same, and different
sections of code have their own ideas of what is a breaking problem.  A
module/library/component/whatever treats any input into itself as its
input, and thus appropriately throws exceptions on bad input.  But code
using that whatever may be perfectly fine handling exceptions coming from
there.

Exceptions need to be appropriate to the given abstraction, and dealt with
by the user of that abstraction.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20140930/5271274d/attachment.html>


More information about the Digitalmars-d mailing list