Exception Handling

Zulq Alam zulq at orange.net
Mon Mar 20 20:12:27 UTC 2006


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

In Java I would do something like

try {
    somObject.foo();
}
catch (FooError e) {
    // do something specific to FooError
}
catch (UnrelatedToFooError e) {
    // do something specific to UnrelatedToFooError
}

Even if under the hood the same is happening this seems to take care of 
some very common code.

Is there something in Smalltalk/Squeak will provide something similar?

Thanks,
Zulq.




More information about the Squeak-dev mailing list