About use of specific error
tim Rowledge
tim at rowledge.org
Fri Mar 3 21:37:40 UTC 2006
On 3-Mar-06, at 12:50 PM, Peter Crowther wrote:
>> From: stéphane ducasse
>> In Java you
>> get really a lot of exceptions everywhere. The comparison is
>> interesting.
>
> Java has had exceptions since the language was devised. In
> Smalltalk, and especially in Squeak, exceptions are recent additions.
Kinda; exceptions went into ParcPlace Smalltalk in about 1990; I
remember spending several weeks implementing the primitives and VM
stackhandling support in the BrouHaHa/Archimedes Smalltalk system.
Squeak has had the basics of exceptions for quite a while too BUT it
doesn't seem that anyone has really bothered to make much decent use
of them. It's like proper Closures - we've had code to provide them
for ages and yet haven't actually got them into the system properly.
> I suspect the reason that Smalltalk error handling has grown up the
> way it has, with variants of methods that don't throw the
> exception, is because error: didn't give the option of handling the
> problem - your code simply failed. A Squeak exception hierarchy
> has not been constructed because we're still moving over from a 30-
> year-old legacy of throwing the user into the debugger rather than
> handling the exception somewhere in the call stack.
I think that expresses it extremely well.
Raising an exception gives code higher up the food chain a chance to
do something sensible without alarming a possibly naive - or absent,
think headless server - user without good cause. A good specific
exception provides useful information just like a class does. How
good would Smalltalk be if all our objects were the same and relied
on having an instvar that was a string naming the class we should
treat it as? I guess you could make a system like that but I doubt
I'd enjoy using it.
My view is that low level code should raise exceptions (like say
DiskGoneMissingException) than higher level code (like
DatabaseAccessor) catches and handles. If there is something the
handling cannot deal with then a new exception can be raised
(DatabaseUnableToAccessException?) which the higher application might
trap and handle by letting the user know of the problem. Users should
never see walkbacks because of some low-level problem.
tim
--
tim Rowledge; tim at rowledge.org; http://www.rowledge.org/tim
Oxymorons: Government organization
More information about the Squeak-dev
mailing list
|