Way of indicating an error

J J azreal1977 at hotmail.com
Tue Mar 6 18:58:04 UTC 2007


+1.  A lot of smalltalk things seem to be this way.  Has a default 
(sometimes throw error, sometimes return nil), but allows the client to 
override the default easily.

>From: "Ramon Leon" <ramon.leon at allresnet.com>
>Reply-To: The general-purpose Squeak developers 
>list<squeak-dev at lists.squeakfoundation.org>
>To: "'The general-purpose Squeak developers 
>list'"<squeak-dev at lists.squeakfoundation.org>
>Subject: RE: Way of indicating an error
>Date: Mon, 26 Feb 2007 09:09:58 -0700
>
> > Hi,
> >
> > if a method should compute and return a value. If this method
> > detects an error in its process what is the best way to indicate it:
> >
> > - returning nil instead of the computed value
> > - raise a specific error
> >
> >
> > Bye
> >
> > --
> > Damien Cassou
>
>I like how detect works.  If you don't pass a handler, raise an error
>
>^#(John Doe) detect: [:each | each = 'Ramon'] => Error: Object is not in 
>the
>collection
>
>If you want to handle the error, don't catch it, make another method that
>takes the handler as an arg so the api is cleaner, so the client doesn't
>have to catch it.
>
>^#(John Doe) detect: [:each | each = 'Ramon'] ifNone:['']
>
>Then you can return nil via the handler if you like, or just handle the
>error some other way like returning an empty string, or don't pass a 
>handler
>and let the exception propagate.
>
>Ramon Leon
>http://onsmalltalk.com
>
>

_________________________________________________________________
Find a local pizza place, movie theater, and more….then map the best route! 
http://maps.live.com/?icid=hmtag1&FORM=MGAC01




More information about the Squeak-dev mailing list