About use of specific error

Markus Gaelli gaelli at emergent.de
Thu Mar 2 13:36:30 UTC 2006


>>
>> 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.

Ok, I had some nice discussions about that subject in basically all  
my Java classes I had to give... guess I was mixing that up a bit. ;-)
Students love to throw and catch exceptions.

For whom it might concern, there is

> 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).
Don't know. As Error is a subclass of Exception there shouldn't be  
much trouble.

The only three types of exception handling code, that come to my mind  
now, and which I understand, are:

- External IO access, which might fail during the call
- Unit-Tests to check if preconditions are _failing_ correctly
- The _one_ most outer exception-handling code in a deployed  
application, which translates an ugly walkback/red screen/whatever  
into a nice message to the user to calm down, everything will be  
fixed, and to call that number of the helpdesk...

Any I forgot?

Btw., Java folks (in this case Bruce-"Thinking in C++/Java"-Eckel)  
came up with funny ways _not_ to be forced to have exception handling  
code:
http://www.mindview.net/Etc/Discussions/CheckedExceptions

Cheers,

Markus


>>
>> 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