About use of specific error
stéphane ducasse
ducasse at iam.unibe.ch
Thu Mar 2 13:15:09 UTC 2006
On 2 mars 06, at 13:49, Markus Gaelli wrote:
> Hi Boris,
>
>>> The consequence is that it can be tedious to capture only specific
>>> error.
>> Yes, it is often necessary to ask an exception for its message
>> text to understand what happened.
>
> Could you give an example please?
>
> I am still not convinced that the idiom of "first (possibly)
> hitting the wall, and then asking for the door" is a good one to
> teach students programming.
I was not talking about teaching anything.
I just asked them to write tests and I was surprised that I have to
catch always Error and not more precise Exception.
> I think it would be better to teach students a _defensive_ way of
> programming, that is to ask first, if everything is ok, using some
> boolean queries and if these queries do not exist, let them write
> these queries and _not_ exception hierarchies.
>
> Exceptions are a way of goto programming and can become quite hairy
> to use. I am glad to be in sync here with Andrew Thomas and Dave
> Hunt in their nice book about the pragmatic programmer.
> They write something like using exceptions should be actually saved
> for situations, the developer cannot predict, such as external io-
> failures etc.
Still in Squeak you have error in collections and read the email of
Boris this is interesting to ask ourselves the question.
> I am all for letting the programmers know which precondition they
> violated calling a method, but only for debugging their code, and
> not for using that info _in_ their code.
I do not like exception either (but catching too high exception
forces you to typecheck them anyway to do something).
>
> I am aware that there is a slight performance penalty to ask if
> everything is ok first all the times, also when everything _is_ ok.
> But I'd teach above idiom more as the exception than as the
> rule... ;-) -- if at all.
>
> Cheers,
>
> Markus
>
>
More information about the Squeak-dev
mailing list
|