<div dir='auto'><div>Fyio - here is a practical example of resignaling an exception (but I won't guarantee that it's idiomatic): https://sourcegraph.com/search?q=context:global+repo:%5Egithub%5C.com/LinqLover/TelegramBot%24%40098a29b+deferDuring&patternType=literal<div dir="auto"><br></div><div dir="auto">I suppose that it's broken now, but I haven't checked yet.</div><br><div class="gmail_extra"><br><div class="gmail_quote">Am 11.06.2022 00:21 schrieb Jaromir Matas <mail@jaromir.net>:<br type="attribution"><blockquote class="quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">
<div>
<p>Hi Christoph,</p>
<p>Yes, the “fresh copy” of an exception is probably the best and simplest solution and you and Chris were right! I forgot about the subclasses and their instance variables :)</p>
<p> </p>
<p>So what would you think about this simple fix:</p>
<p> </p>
<p>#signal</p>
<p>                "Ask ContextHandlers in the sender chain to handle this signal.  The default is to execute and return my defaultAction.</p>
<p>                Sending #signal to an already signaled exception generates a new exception of the same type with the same messageText"</p>
<p> </p>
<p>                signalContext ifNotNil: [^self copy refresh signal].
</p>
<p>                signalContext := thisContext contextTag.</p>
<p>                ^(thisContext nextHandlerContextForSignal: self) handleSignal: self</p>
<p> </p>
<p>… where:</p>
<p> </p>
<p>#refresh</p>
<p>                signalContext := handlerContext := outerContext := nil</p>
<p> </p>
<p> </p>
<p> </p>
<div style="border:none;border-top:solid #e1e1e1 1pt;padding:3pt 0in 0in 0in">
<p style="border:none;padding:0in"><b>From: </b><a href="mailto:mail@jaromir.net">Jaromir Matas</a><br>
<b>Sent: </b>Friday, June 10, 2022 23:56<br>
<b>To: </b><a href="mailto:squeak-dev@lists.squeakfoundation.org">The general-purpose Squeak developers list</a><br>
<b>Subject: </b>Re: [squeak-dev] Re-signalling an already signaled exception</p>
</div>
<p> </p>
<p>Hi Christoph,</p>
<p>I think I remember… My original interpretation of ANSI about sending #signal to an existing exception resulted in Kernel-jar.1407. However, later I noticed this wording in #messageText section:</p>
<p style="margin-left:0.5in">“Subsequent sends of the message #messageText to a signaled exception generated by sending the message #signal to the receiver of this message will also return this value.”</p>
<p>… this “generated by” lead me to a more limited/conservative interpretation that is currently in the Trunk.</p>
<p> </p>
<p>I believe Kernel-jar.1407 could be considered an extension of ANSI specification - your example indicates it’d be probably more logical or practical than the current one. I haven’t seen re-sending signal to existing exceptions implemented
 in other systems though.</p>
<p> </p>
<p>How about to try after the release? :)</p>
<p>Thanks for bringing this up!</p>
<p>Best,</p>
<p>jaromir </p>
<p> </p>
<p> </p>
<div style="border:none;border-top:solid #e1e1e1 1pt;padding:3pt 0in 0in 0in">
<p><b>From: </b><a href="mailto:mail@jaromir.net">Jaromir Matas</a><br>
<b>Sent: </b>Friday, June 10, 2022 17:18<br>
<b>To: </b><a href="mailto:squeak-dev@lists.squeakfoundation.org">The general-purpose Squeak developers list</a><br>
<b>Subject: </b>Re: [squeak-dev] Re-signalling an already signaled exception</p>
</div>
<p> </p>
<p>Hi Christoph,</p>
<p> </p>
<p>Thanks for the example! This was actually my original idea how re-signaling an existing exception should work :) It’s implemented in Kernel-jar.1407 (now in Treated) - check it out… it really returns
</p>
<p style="text-indent:0.5in">`Key not found: plonk`</p>
<p>as you would expect too.</p>
<p>Unfortunately I can’t recall why I went with the less ambitious Kernel-jar.1446 (now in Trunk) eventually.</p>
<p>If you find this more reasonable, why not try to revive it?</p>
<p>Thank you,</p>
<p>best,</p>
<p>Jaromir</p>
<p> </p>
<div style="border:none;border-top:solid #e1e1e1 1pt;padding:3pt 0in 0in 0in">
<p><b>From: </b><a href="mailto:Christoph.Thiede@student.hpi.uni-potsdam.de">christoph.thiede@student.hpi.uni-potsdam.de</a><br>
<b>Sent: </b>Friday, June 10, 2022 13:30<br>
<b>To: </b><a href="mailto:squeak-dev@lists.squeakfoundation.org">squeak-dev@lists.squeakfoundation.org</a><br>
<b>Subject: </b>Re: [squeak-dev] Re-signalling an already signaled exception</p>
</div>
<p> </p>
<p>Hi Jaromir,<br>
<br>
Thanks for working on this! I'm possibly a bit late on the party, but I noticed that current #signal only keeps the messageText, not any other custom properties of an exception. I'm not sure whether this is the expected behavior. :)<br>
<br>
Think of this revised example:<br>
<br>
    [(KeyNotFound key: #plonk) signal] on: Error do: [:ex |<br>
        [ex signal] on: KeyNotFound do: [:ex2 | Transcript show: ex2]]<br>
<br>
It will print out "Key not found: nil" to the Transcript, instead of printing the original key.<br>
<br>
Without diving deeper into this discussion, my first impression would have been that some kind of #freshCopy (maybe with a better name?) would be a more holistic approach to honor any state in subclasses of Exception. What do you think? :-)<br>
<br>
Best,<br>
Christoph<br>
<br>
<span style="color:gray">---<br>
<i>Sent from </i></span><a href="https://github.com/hpi-swa-lab/squeak-inbox-talk"><i><span style="color:gray">Squeak Inbox Talk</span></i></a><br>
<br>
On 2022-02-06T11:42:46+01:00, mail@jaromir.net wrote:<br>
<br>
> Hi,<br>
> just an update: I've sent a proposal to the Inbox: Kernel-jar.1446 with the following code:<br>
> <br>
> signal<br>
>     "Ask ContextHandlers in the sender chain to handle this signal. The default is to execute and return my defaultAction.<br>
>     Sending #signal to an already signaled exception generates a new exception of the same type with the same messageText"<br>
> <br>
>     signalContext ifNotNil: [^self class signal: messageText]. <br>
>     signalContext := thisContext contextTag.<br>
>     ^(thisContext nextHandlerContextForSignal: self) handleSignal: self<br>
> <br>
> If possible I'd like to withdraw my previous contribution to #signal making repeated #signal sends equivalent to sending #outer, to prevent future code from using that misleading approach. Subsequent #signal sends are NOT equivalent to #outer and they have
 their own subtly different meaning discussed here - provided my interpretation of ANSI is right this time :)<br>
> <br>
> Thanks for your time and apologies for previous confusion.<br>
> <br>
> best, <br>
> Jaromir<br>
> ^[^ <br>
> --<br>
> Sent from Squeak Inbox Talk<br>
> <br>
> On 2022-02-05T18:48:39+01:00, mail at jaromir.net wrote:<br>
> <br>
> > Hi Chris,<br>
> > <br>
> > On 2022-02-04T17:11:35-06:00, asqueaker at gmail.com wrote:<br>
> > <br>
> > > Hi Jaromir,<br>
> > > <br>
> > > Here's a motivation example:<br>
> > > ><br>
> > > > [1/0] on: Error do: [:ex |<br>
> > > > [ex signal] on: ZeroDivide do: [Transcript show: #ZeroDivide]<br>
> > > > ]<br>
> > > ><br>
> > > > Would you expect this code to work and pick up the ZeroDivide handler?<br>
> > > ><br>
> > > ...<br>
> > > <br>
> > > > The point or a use case is to provide additional (finer, more specific)<br>
> > > > handlers inside the general handler rather than wrap the general handler<br>
> > > > inside more specific handlers. More specific handlers can even be inside a<br>
> > > > method so the readability would not degrade.<br>
> > > ><br>
> > > <br>
> > > I was able to do it by creating a new exception instance and signaling it:<br>
> > > <br>
> > > [1/0] on: Error do: [: err |<br>
> > > [err copy signal] on: ZeroDivide do: [Transcript show:<br>
> > > #ZeroDivide] ]<br>
> > > <br>
> > > I don't know about #copy, though, you might want to implement your own<br>
> > > special #freshCopy that throws out the signalContext, handlerContext and<br>
> > > outerContext, but the above "worked". :)<br>
> > > <br>
> > <br>
> > Precisely, it crossed my mind too and yes, it has to be a "fresh" copy with blank instance variables (except messageText). A simple copy fails tests with nested outer etc...<br>
> > <br>
> > I've checked ANSI again and they say, quote: [5.5.3.1 messageText][...] Subsequent sends of of the message #messageText to a signaled exception generated by sending the message #signal to the receiver of this message [note: the receiver is an exception
 instance] will also return this value.<br>
> > <br>
> > So what I'm actually looking for is this: (and it's equivalent to the "fresh" copy idea)<br>
> > <br>
> > [1/0] on: Error do: [: err | <br>
> > [err class signal: err messageText] on: ZeroDivide do: [Transcript show: #ZeroDivide] ]<br>
> > <br>
> > If I'm interpreting ANSI's intention correctly then we could update our #signal like this:<br>
> > <br>
> > signal<br>
> >     "Ask ContextHandlers in the sender chain to handle this signal. The default is to execute and return my defaultAction.<br>
> >     Signaling an already signaled exception is interpreted as signaling a new exception of the same type with the same messageText"<br>
> > <br>
> > -    signalContext ifNotNil: [^self outer].<br>
> > +    signalContext ifNotNil: [^self copy signal: self messageText]. <br>
> >     signalContext := thisContext contextTag.<br>
> >     ^(thisContext nextHandlerContextForSignal: self) handleSignal: self<br>
> > <br>
> > It was my idea last year to make subsequent sends of #signal to an already signaled exception equivalent to #outer and now I can see it was wrong and I'd like to really fix it this time :) All test are green, even the ones in Tests-jar.464.<br>
> > <br>
> > Thanks, Chris, for discussing this.<br>
> > <br>
> > best, <br>
> > Jaromir<br>
> > ^[^ <br>
> > --<br>
> > Sent from Squeak Inbox Talk<br>
> > <br>
> ><br>
> <br>
> </p>
<p> </p>
<p> </p>
<p> </p>
</div>
</div>
</blockquote></div><br></div></div></div>