[squeak-dev] Re-signalling an already signaled exception
Chris Muller
asqueaker at gmail.com
Fri Feb 4 23:11:35 UTC 2022
Hi Jaromir,
Here's a motivation example:
>
> [1/0] on: Error do: [:ex |
> [ex signal] on: ZeroDivide do: [Transcript show: #ZeroDivide]
> ]
>
> Would you expect this code to work and pick up the ZeroDivide handler?
>
...
> The point or a use case is to provide additional (finer, more specific)
> handlers inside the general handler rather than wrap the general handler
> inside more specific handlers. More specific handlers can even be inside a
> method so the readability would not degrade.
>
I was able to do it by creating a new exception instance and signaling it:
[1/0] on: Error do: [: err |
[err copy signal] on: ZeroDivide do: [Transcript show:
#ZeroDivide] ]
I don't know about #copy, though, you might want to implement your own
special #freshCopy that throws out the signalContext, handlerContext and
outerContext, but the above "worked". :)
> Does this make sense?
>
Another option seems you could dispatch your handler (or double-dispatch)
to the signaled Exception.
- Chris
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20220204/01febd5a/attachment.html>
More information about the Squeak-dev
mailing list
|