Exceptions (Was RE: [ANN] Cleaned up KomHttpServer on SM)

Ned Konz ned at squeakland.org
Fri Nov 5 16:16:58 UTC 2004


[ sorry, hit Ctrl-Enter when I wasn't done yet ]

On Thursday 04 November 2004 8:11 pm, Russell Penney wrote:
>    Thanks for the comments. If you do have to handle an Exceptions down in
> the bowels of your code, is it better to perhaps handle the Exception and
> then signal a more general Exception so that code further up can still
> detect something has gone wrong?

The proper approach is to make specific Exception subclasses that have the 
desired default behavior, so if they aren't caught, something reasonable 
happens anyway.

Alternatively (that is, if you have to deal with Errors or Exception types 
that don't have the right default behavior), an idiom that I've used from 
time to time is:

[ some code ]
 on: Error
 do: [ :ex | ex isNested
 ifTrue: [ "another handler on the stack" ex pass ]
 ifFalse: [ "do something yourself rather than the default" ]].

Which can be used to make something like #onUnhandledErrorDo:.

-- 
Ned Konz
http://bike-nomad.com/squeak/



More information about the Squeak-dev mailing list