Maybe the abstraction needed wraps everything within a single handler,
but internally does a switch like statement dispatching to a
particular error handler block.

handledBlock
  exceptionDispatcher
    on: NotFoundError do: [:ex | ...];
    on: MessageNotUnderstood do: [:ex | .. ].

BlockClosure>>exceptionDispatcher

| exceptionDispatcher|
exceptionDispatcher:= ExceptionDispatcher new.
self on: Exception do: [:ex | dispatcher handle: ex ].
^exceptionDispatcher


ExceptionDispatcher>>on: exceptionClass do: aBlock
  self handlers add: exceptionClass -> aBlock

The #exceptionDispatcher method would return this special object that
deals with the resolution of each exception class (how to sort them
would't be trivial unless done naively). But any resignalling would be
only one level deep.

Disclaimer: I just wrote the code as I replied this email, not
guaranteed to work :)


Esteban A. Maringolo

El lun., 8 abr. 2019 a las 10:09, jtuc...@objektfabrik.de
(<jtuc...@objektfabrik.de>) escribió:
>
> Am 08.04.19 um 14:39 schrieb Richard O'Keefe:
>
>
>> >
>> > It's easy enough to add your own methods like
>> > on: exn1 do: act1 on: exn2 do: act2
>> >     "An imperfect emulation of VAST's #when:do:when:do:"
>> >     ^[self on: exn1 do: act1] on: exn2 do: act2
>> >
>> > on: exn1 do: act1 on: exn2 do: act2 on: exn3 do: act3
>> >     "An imperfect emulation of VAST's #when:do:when:do:when:do:"
>> >     ^[[self on: exn1 do: act1] on: exn2 do: act2] on: exn3 do: act3
>> > to BlockClosure.  It won't be fast, but your code might be
>> > clearer.
>
> well, an unwanted side effect might be that the handling of exn1 is also 
> guarded by the outer on:do: .
>
> Not that this has to be a problem but it introduces new things to think about 
> when you want to #resignalAs: and such.
>
>
> --
> -----------------------------------------------------------------------
> Objektfabrik Joachim Tuchel          mailto:jtuc...@objektfabrik.de
> Fliederweg 1                         http://www.objektfabrik.de
> D-71640 Ludwigsburg                  http://joachimtuchel.wordpress.com
> Telefon: +49 7141 56 10 86 0         Fax: +49 7141 56 10 86 1
>
>

Reply via email to