Exception Handling
nicolas cellier
ncellier at ifrance.com
Mon Mar 20 20:41:54 UTC 2006
Le Lundi 20 Mars 2006 21:12, Zulq Alam a écrit :
> Hello,
>
> I'm a bit confused about exception handling, perhaps you can help please?
>
> If I have a method #foo and #foo can signal two errors FooError and
> UnrelatedToFooError how do I handle both errors using #on:do: without
> having something like...
>
> [someObject foo]
> on: Error
> do: [:error | (error class = FooError) ifTrue: ["do something
> specific to FooError"].
> (error class = UnrelatedToFooError) ifTrue: ["do something
> specific to UnrelatedToFooError"]].
>
If handler blocks are different, you might nest the two
[[someObject foo]
on: FooError
do: [:error | "do something specific to FooError"]]
on: UnrelatedToFooError
do: [:error | "do something specific to UnrelatedToFooError"].
It's a little like the if/elseif chain, you have to nest them in Smalltalk.
Otherwise, you could try and implement your own multiple error messages
on:do:on:do:
on:do:on:do:on:do:
If handler blocks are the same, there is the possibility to handle a
collection of errors in Visualworks,
[someObject foo]
on: FooError , UnrelatedToFooError
do: [:error | "do something common to FooError and
UnrelatedToFooError"].
but i did not see anything like this in Squeak... unless i missed something.
Has anyone got elegant a solution for the second case ?
Nicolas
More information about the Squeak-dev
mailing list
|