On 25 oct. 2013, at 13:34, Norbert Hartl <
[hidden email]> wrote:
> I’m thinking about what would be the proper/least annoying way of having multiple exception sections. If I have a code block that can emit two different exceptions is the only way doing it
>
> [ [ ... ]
> on: Exception1
> do: [ … ] ]
> on: Exception2
> do: [ … ]
You can handle multiple exceptions like that:
[ ... ] on: Exception1, Exception2 do: [ :err | ... ]
But there is only one handling block.
If you need to have two different handling blocks, I once though of a solution where you would write things like that:
[ ... ] exceptionHandler
on: Exception1 do: [ ... ];
on: Exception2 do: [ ... ];
execute.
The #exceptionHandler message would answer an ExceptionHandler on the block that would be able to manage multiple handling blocks.
Something like that:
ExceptionHandler >> on: anExceptionClass do: aBlock
handlingBlock at: anExceptionClass put: aBlock
ExceptionHandler>> handlingBlockFor: anExceptionClass
anExceptionClass ifNil: [ ^ nil ].
^ handlingBlock
at: anExceptionClass
ifAbsent: [ self handlingBlockFor: anExceptionClass superclass ]
ExceptionHandler >>#execute
block on: Error do: [ :error |
(self handlingBlockFor: error class)
ifNil: [ error pass ]
ifNotNil: [ :handlingBlock | handlingBlock value ] ]
> on:do: just calls a primitive that marks the context being an exception handler. What is called in the image when the stack is scanned to find an exception handler?
I think its ContextPart>>#findNextHandlerContextStarting
>
> thanks,
>
> Norbert