<div dir="ltr"><div dir="ltr"><div dir="ltr">Hello Jaromir, all, <div>Change affects re-signaling exceptions of the same kind, line below falls into endless loop in Trunk. It works differently in Squeak 5.3 or 4.2:</div><div>[Error new signal: 'some error'] on: Error do: [:e | e resignalAs: (DomainError new messageText: 'some domain error')].</div><div>regards,</div><div>Vaidotas</div><div><br></div></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, Feb 4, 2022 at 4:15 PM <<a href="mailto:mail@jaromir.net">mail@jaromir.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Jakob, all,<br>
<br>
I give up this experiment of mine; I've realized using #restartWithNewReceiver is tricky and very non-OOP: replacing a receiver with an object of a different type introduces unexpected consequences and checking the type of the replacement object is so not-object-oriented; the best I could come up with is:<br>
<br>
resignalAs: replacementException<br>
        "Signal an alternative exception in place of the receiver."<br>
<br>
        (replacementException isKindOf: Exception class) ifTrue: [^self resignalAs: replacementException new].<br>
        (replacementException isKindOf: Exception) ifFalse: [^self error: 'wrong replacementException type'].<br>
        signalContext restartWithNewReceiver: replacementException<br>
<br>
This would be a clean implementation of ANSI's #resignalAs with a nice stack when debugging; compare with the confusing stack currently produced for e.g.:<br>
<br>
        [self error] on: Error do: [:ex | ex resignalAs: Warning new]<br>
<br>
Besides, the current implementation allows nonsense like this evaluate silently:<br>
<br>
        [self error] on: Error do: [:ex | ex resignalAs: Semaphore new] <br>
<br>
but it probably doesn't do much harm and doesn't justify changing the current simple implementation.<br>
<br>
So unless someone sees any value in the above implementation I won't clutter the Inbox :)<br>
<br>
Thanks.<br>
<br>
best, <br>
Jaromir<br>
^[^    <br>
  --<br>
Sent from Squeak Inbox Talk<br>
<br>
On 2022-01-29T21:43:17+01:00, <a href="mailto:mail@jaromir.net" target="_blank">mail@jaromir.net</a> wrote:<br>
<br>
> Hi Jakob, <br>
>       a correction:<br>
> <br>
> > > As so often, the breaking of applications that relied on the<br>
> > > non-standard behavior may be an obstacle.<br>
> > Yes indeed, that's a pain... theoretically as a workaround a class method could be added to create an instance and send it the instance side #resignalAs. <br>
> <br>
> Sorry, ignore me please, no class method indeed, but something like this:<br>
> <br>
> resignalAs: replacementException<br>
>       "Abort an exception handler and signal an alternative exception in place of the receiver.<br>
>        Allow an exception class as replacementException as an extension of ANSI specification:<br>
>               [1/0] on: Error do: [:ex | ex resignalAs: Warning new]    <--- ANSI compliant<br>
>               [1/0] on: Error do: [:ex | ex resignalAs: Warning]           <--- Squeak extension"<br>
> <br>
>       (replacementException isKindOf: Exception class) ifTrue: [<br>
>               self resignalAs: replacementException new].<br>
>       signalContext restartWithNewReceiver: replacementException<br>
> <br>
> a bit ugly... Or keep it simple, no extension?<br>
> <br>
> resignalAs: replacementException<br>
>       "Abort an exception handler and signal an alternative exception in place of the receiver."<br>
> <br>
>       signalContext restartWithNewReceiver: replacementException<br>
> <br>
> best,<br>
> ~~~<br>
> ^[^    Jaromir<br>
> <br>
> Sent from Squeak Inbox Talk<br>
> <br>
> On 2022-01-29T20:18:40+01:00, mail at <a href="http://jaromir.net" rel="noreferrer" target="_blank">jaromir.net</a> wrote:<br>
> <br>
> > Hi Jakob,<br>
> > <br>
> > thanks for your reply. <br>
> > <br>
> > The proposed change is not supposed to change the semantics of resignalAs in any way (except limiting the argument to an exception instance, not a class).<br>
> > <br>
> > We already have 3 resignalAs tests - is this ok? Pharo/Cuis are behind Squeak and as for VW I'm not familiar with their testing just yet.<br>
> > <br>
> > The tests are green; well, after fixing my own contribution from last year (doubleOuterResignalAsTest) where I erroneously used a class as #resignalAs's argument - what a shame :) I'll definitely send a fix of this test to the Inbox.<br>
> > <br>
> > > As so often, the breaking of applications that relied on the<br>
> > > non-standard behavior may be an obstacle.<br>
> > Yes indeed, that's a pain... theoretically as a workaround a class method could be added to create an instance and send it the instance side #resignalAs. However looking at its senders this method doesn't feel like frequently used :) (VA didn't even bother to implement it, at least in the version I have)<br>
> > <br>
> > best,<br>
> > ~~~<br>
> > ^[^    Jaromir<br>
> > <br>
> > Sent from Squeak Inbox Talk<br>
> > <br>
> > On 2022-01-29T18:53:24+01:00, jakres+squeak at <a href="http://gmail.com" rel="noreferrer" target="_blank">gmail.com</a> wrote:<br>
> > <br>
> > > Hi Jaromir,<br>
> > > <br>
> > > We should start with a test case. I agree with your interpretation of<br>
> > > the standard and see no harm in an inbox submission.<br>
> > > Is there some ANSI Smalltalk test suite out there that could be shared<br>
> > > between the dialects?<br>
> > > <br>
> > > As so often, the breaking of applications that relied on the<br>
> > > non-standard behavior may be an obstacle.<br>
> > > <br>
> > > Kind regards,<br>
> > > Jakob<br>
> > > <br>
> > > Am Sa., 29. Jan. 2022 um 17:43 Uhr schrieb <mail at <a href="http://jaromir.net" rel="noreferrer" target="_blank">jaromir.net</a>>:<br>
> > > ><br>
> > > > Hi all,<br>
> > > ><br>
> > > > I think Squeak's implementation of #resignalAs: is not following the ANSI specification precisely. Currently it reads:<br>
> > > ><br>
> > > > resignalAs: replacementException<br>
> > > ><br>
> > > >         signalContext resumeEvaluating: [replacementException signal]<br>
> > > ><br>
> > > > ANSI says:<br>
> > > > "<br>
> > > > The active exception action is aborted and the exception environment *and the evaluation context*<br>
> > > > are restored to the same states that were in effect when the receiver was originally signaled.<br>
> > > > This message (i.e. resignalAs:) causes the replacementException to be treated as if it had been originally<br>
> > > > signaled instead of the receiver.<br>
> > > > "<br>
> > > ><br>
> > > > This is very similar to #retry (or #retryUsing:) specification so I'd suggest the following implementation:<br>
> > > ><br>
> > > > resignalAs: replacementException<br>
> > > ><br>
> > > >         signalContext restartWithNewReceiver: replacementException<br>
> > > ><br>
> > > > The current implementation leads to building the new resignaled contexts on top of the previous signal contexts (and the resignalAs context itself) instead of simply *restarting* the previous signal context with the replacement exception as the new receiver. In my opinion the suggested implementation precisely follows the ANSI specification, and is consistent with current #retry and #retryUsing: implementation - compare:<br>
> > > ><br>
> > > > retryUsing: alternativeBlock<br>
> > > >         "Abort an exception handler and evaluate a new block in place of the handler's protected block."<br>
> > > ><br>
> > > >         handlerContext restartWithNewReceiver: alternativeBlock<br>
> > > ><br>
> > > > Other dialects: Pharo and Cuis copied Squeak's but VW implemented resignalAs: to comply with ANSI precisely.<br>
> > > ><br>
> > > > One consideration: the current implementation allows "exception resignalAs: Error", i.e. allows Exception class as an argument but ANSI's version requires "exception resignalAs: Error new". All senders (there are just a few) in the base image seem use "Error new" anyway.<br>
> > > ><br>
> > > > My arguments for are: consistency, readability and less complexity (especially while debugging)<br>
> > > ><br>
> > > > What do you think? Inbox it?<br>
> > > ><br>
> > > > best,<br>
> > > > ~~~<br>
> > > > ^[^    Jaromir<br>
> > > ><br>
> > > > Sent from Squeak Inbox Talk<br>
> > > ><br>
> > > <br>
> > ><br>
> > <br>
> ><br>
> <br>
> <br>
<br>
</blockquote></div>