Semantics of #resignalAs:

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Semantics of #resignalAs:

NorbertHartl
What are the semantics of Exception>>#resignalAs: regarding active exception handler? Isn't the active exception handler excluded from being treated again? Taking the example

| counter |
counter := 0.
[ 1/0 ]
        on: Error
        do: [ :e |
                counter := counter + 1.
                counter > 1 ifTrue: [ self halt ].
                e resignalAs: NotFound new ].

should it just run and end? Or should the debugger pop up?

thanks,

Norbert


Reply | Threaded
Open this post in threaded view
|

Re: Semantics of #resignalAs:

jtuchel
Norbert,

I'd say you get a NotFound Exception.

Joachim



> Am 23.07.2015 um 16:20 schrieb Norbert Hartl <[hidden email]>:
>
> What are the semantics of Exception>>#resignalAs: regarding active exception handler? Isn't the active exception handler excluded from being treated again? Taking the example
>
> | counter |
> counter := 0.
> [ 1/0 ]
>    on: Error
>    do: [ :e |
>        counter := counter + 1.
>        counter > 1 ifTrue: [ self halt ].
>        e resignalAs: NotFound new ].
>
> should it just run and end? Or should the debugger pop up?
>
> thanks,
>
> Norbert
>
>
>

Reply | Threaded
Open this post in threaded view
|

Re: Semantics of #resignalAs:

NorbertHartl

> Am 23.07.2015 um 17:54 schrieb Joachim Tuchel <[hidden email]>:
>
> Norbert,
>
> I'd say you get a NotFound Exception.
>
In pharo you get a debugger. Meaning this piece of code is actively an endless loop.

Norbert

> Joachim
>
>
>
>> Am 23.07.2015 um 16:20 schrieb Norbert Hartl <[hidden email]>:
>>
>> What are the semantics of Exception>>#resignalAs: regarding active exception handler? Isn't the active exception handler excluded from being treated again? Taking the example
>>
>> | counter |
>> counter := 0.
>> [ 1/0 ]
>>   on: Error
>>   do: [ :e |
>>       counter := counter + 1.
>>       counter > 1 ifTrue: [ self halt ].
>>       e resignalAs: NotFound new ].
>>
>> should it just run and end? Or should the debugger pop up?
>>
>> thanks,
>>
>> Norbert
>>
>>
>>
>


Reply | Threaded
Open this post in threaded view
|

Re: Semantics of #resignalAs:

jtuchel
In reply to this post by NorbertHartl
Norbert,

Sorry if this is a stupid question: what does the debugger say?

I mean, assuming NotFound is an Exception, I'd expect a debugger showing a NotFound Error...

Joachim

Am 23.07.2015 18:34 schrieb Norbert Hartl <[hidden email]>:

>
>
> > Am 23.07.2015 um 17:54 schrieb Joachim Tuchel <[hidden email]>:
> >
> > Norbert,
> >
> > I'd say you get a NotFound Exception.
> >
> In pharo you get a debugger. Meaning this piece of code is actively an endless loop.
>
> Norbert
>
> > Joachim
> >
> >
> >
> >> Am 23.07.2015 um 16:20 schrieb Norbert Hartl <[hidden email]>:
> >>
> >> What are the semantics of Exception>>#resignalAs: regarding active exception handler? Isn't the active exception handler excluded from being treated again? Taking the example
> >>
> >> | counter |
> >> counter := 0.
> >> [ 1/0 ]
> >>   on: Error
> >>   do: [ :e |
> >>       counter := counter + 1.
> >>       counter > 1 ifTrue: [ self halt ].
> >>       e resignalAs: NotFound new ].
> >>
> >> should it just run and end? Or should the debugger pop up?
> >>
> >> thanks,
> >>
> >> Norbert
> >>
> >>
> >>
> >
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Semantics of #resignalAs:

NorbertHartl
In reply to this post by NorbertHartl
You get a debugger at the position if the halt in the code. Meaning the exception block run more than once. And it would run forever.

Norbert



> Am 23.07.2015 um 18:46 schrieb Joachim Tuchel <[hidden email]>:
>
> Norbert,
>
> Sorry if this is a stupid question: what does the debugger say?
>
> I mean, assuming NotFound is an Exception, I'd expect a debugger showing a NotFound Error...
>
> Joachim
>
> Am 23.07.2015 18:34 schrieb Norbert Hartl <[hidden email]>:
>>
>>
>>> Am 23.07.2015 um 17:54 schrieb Joachim Tuchel <[hidden email]>:
>>>
>>> Norbert,
>>>
>>> I'd say you get a NotFound Exception.
>> In pharo you get a debugger. Meaning this piece of code is actively an endless loop.
>>
>> Norbert
>>
>>> Joachim
>>>
>>>
>>>
>>>> Am 23.07.2015 um 16:20 schrieb Norbert Hartl <[hidden email]>:
>>>>
>>>> What are the semantics of Exception>>#resignalAs: regarding active exception handler? Isn't the active exception handler excluded from being treated again? Taking the example
>>>>
>>>> | counter |
>>>> counter := 0.
>>>> [ 1/0 ]
>>>>    on: Error
>>>>    do: [ :e |
>>>>        counter := counter + 1.
>>>>        counter > 1 ifTrue: [ self halt ].
>>>>        e resignalAs: NotFound new ].
>>>>
>>>> should it just run and end? Or should the debugger pop up?
>>>>
>>>> thanks,
>>>>
>>>> Norbert
>>
>>
>>

Reply | Threaded
Open this post in threaded view
|

Re: Semantics of #resignalAs:

jtuchel
Definitely looks wrong to me... The catching block shouldn't catch
exceptions in itself, and a resignal should never run the block again...

I'll try this in VAST.


Am 23.07.15 um 20:05 schrieb Norbert Hartl:

> You get a debugger at the position if the halt in the code. Meaning the exception block run more than once. And it would run forever.
>
> Norbert
>
>
>
>> Am 23.07.2015 um 18:46 schrieb Joachim Tuchel <[hidden email]>:
>>
>> Norbert,
>>
>> Sorry if this is a stupid question: what does the debugger say?
>>
>> I mean, assuming NotFound is an Exception, I'd expect a debugger showing a NotFound Error...
>>
>> Joachim
>>
>> Am 23.07.2015 18:34 schrieb Norbert Hartl <[hidden email]>:
>>>
>>>> Am 23.07.2015 um 17:54 schrieb Joachim Tuchel <[hidden email]>:
>>>>
>>>> Norbert,
>>>>
>>>> I'd say you get a NotFound Exception.
>>> In pharo you get a debugger. Meaning this piece of code is actively an endless loop.
>>>
>>> Norbert
>>>
>>>> Joachim
>>>>
>>>>
>>>>
>>>>> Am 23.07.2015 um 16:20 schrieb Norbert Hartl <[hidden email]>:
>>>>>
>>>>> What are the semantics of Exception>>#resignalAs: regarding active exception handler? Isn't the active exception handler excluded from being treated again? Taking the example
>>>>>
>>>>> | counter |
>>>>> counter := 0.
>>>>> [ 1/0 ]
>>>>>     on: Error
>>>>>     do: [ :e |
>>>>>         counter := counter + 1.
>>>>>         counter > 1 ifTrue: [ self halt ].
>>>>>         e resignalAs: NotFound new ].
>>>>>
>>>>> should it just run and end? Or should the debugger pop up?
>>>>>
>>>>> thanks,
>>>>>
>>>>> Norbert
>>>
>>>


--
-----------------------------------------------------------------------
Objektfabrik Joachim Tuchel          mailto:[hidden email]
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 | Threaded
Open this post in threaded view
|

Re: Semantics of #resignalAs:

jtuchel
Hi again,

okay, trying in VAST didn't shed much light, because resignalAs: is
implemented as

^self error: 'Not yet implemented'.

;-)))

But here is an excerpt from the method's comment:

     Synopsis:
         Signal an alternative exception in place of the receiver.

      Definition: <signaledException>
         The active exception action is aborted and the exception
environment and the evaluation context
         are restored to the same states that were in effect when the
receiver was originally signaled.

         Restoring the evaluation context may result in the execution of
#ensure: or #ifCurtailed:
         termination blocks.

         After the restoration, signal the replacementException and
execute the exception action as
         determined by the restored exception environment.

         This message causes the replacementException to be treated as
if it had been originally
         signaled instead of the receiver.

         If the replacementException is resumable and its exception
action resumes, control will
         ultimately return from the message that signaled the original
exception.

         Control does not return from this message to the currently
active exception action.


If I understand correctly, the [1/0] should only be run once and never
again, and you should get a NotFound error.

....But:

In VisualWorks, I also get a Halt instead of a MustBeBoolean (I had to
Replace NotFound with something available in VW, so I used MustBeBoolen).


So I am puzzled... Hoping for someone to shed some light on this...

Joachim



Am 24.07.15 um 08:25 schrieb [hidden email]:

> Definitely looks wrong to me... The catching block shouldn't catch
> exceptions in itself, and a resignal should never run the block again...
>
> I'll try this in VAST.
>
>
> Am 23.07.15 um 20:05 schrieb Norbert Hartl:
>> You get a debugger at the position if the halt in the code. Meaning
>> the exception block run more than once. And it would run forever.
>>
>> Norbert
>>
>>
>>
>>> Am 23.07.2015 um 18:46 schrieb Joachim Tuchel
>>> <[hidden email]>:
>>>
>>> Norbert,
>>>
>>> Sorry if this is a stupid question: what does the debugger say?
>>>
>>> I mean, assuming NotFound is an Exception, I'd expect a debugger
>>> showing a NotFound Error...
>>>
>>> Joachim
>>>
>>> Am 23.07.2015 18:34 schrieb Norbert Hartl <[hidden email]>:
>>>>
>>>>> Am 23.07.2015 um 17:54 schrieb Joachim Tuchel
>>>>> <[hidden email]>:
>>>>>
>>>>> Norbert,
>>>>>
>>>>> I'd say you get a NotFound Exception.
>>>> In pharo you get a debugger. Meaning this piece of code is actively
>>>> an endless loop.
>>>>
>>>> Norbert
>>>>
>>>>> Joachim
>>>>>
>>>>>
>>>>>
>>>>>> Am 23.07.2015 um 16:20 schrieb Norbert Hartl <[hidden email]>:
>>>>>>
>>>>>> What are the semantics of Exception>>#resignalAs: regarding
>>>>>> active exception handler? Isn't the active exception handler
>>>>>> excluded from being treated again? Taking the example
>>>>>>
>>>>>> | counter |
>>>>>> counter := 0.
>>>>>> [ 1/0 ]
>>>>>>     on: Error
>>>>>>     do: [ :e |
>>>>>>         counter := counter + 1.
>>>>>>         counter > 1 ifTrue: [ self halt ].
>>>>>>         e resignalAs: NotFound new ].
>>>>>>
>>>>>> should it just run and end? Or should the debugger pop up?
>>>>>>
>>>>>> thanks,
>>>>>>
>>>>>> Norbert
>>>>
>>>>
>
>


--
-----------------------------------------------------------------------
Objektfabrik Joachim Tuchel          mailto:[hidden email]
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 | Threaded
Open this post in threaded view
|

Re: Semantics of #resignalAs:

NorbertHartl
Joachim,

thanks for looking into it. The text is the one from ANSI. I'm also puzzled about the last sentence

"Control does not return from this message to the currently active exception action."

I think it means after the resignalling has been done it does not return after the invocation of the #resignalAs: call. As the original signalling context is restored and only the exception is exchanged it could indeed mean that it only works if the resignalled exception does not share the same class hierarchy as the excpetion the original #on:do: catch. If the resignalled exception is the same class or a subclass of the original one it would loop.

In this case I need to fix Voyage :)

Norbert


> Am 24.07.2015 um 08:38 schrieb [hidden email]:
>
> Hi again,
>
> okay, trying in VAST didn't shed much light, because resignalAs: is implemented as
>
> ^self error: 'Not yet implemented'.
>
> ;-)))
>
> But here is an excerpt from the method's comment:
>
>    Synopsis:
>        Signal an alternative exception in place of the receiver.
>
>     Definition: <signaledException>
>        The active exception action is aborted and the exception environment and the evaluation context
>        are restored to the same states that were in effect when the receiver was originally signaled.
>
>        Restoring the evaluation context may result in the execution of #ensure: or #ifCurtailed:
>        termination blocks.
>
>        After the restoration, signal the replacementException and execute the exception action as
>        determined by the restored exception environment.
>
>        This message causes the replacementException to be treated as if it had been originally
>        signaled instead of the receiver.
>
>        If the replacementException is resumable and its exception action resumes, control will
>        ultimately return from the message that signaled the original exception.
>
>        Control does not return from this message to the currently active exception action.
>
>
> If I understand correctly, the [1/0] should only be run once and never again, and you should get a NotFound error.
>
> ....But:
>
> In VisualWorks, I also get a Halt instead of a MustBeBoolean (I had to Replace NotFound with something available in VW, so I used MustBeBoolen).
>
>
> So I am puzzled... Hoping for someone to shed some light on this...
>
> Joachim
>
>
>
> Am 24.07.15 um 08:25 schrieb [hidden email]:
>> Definitely looks wrong to me... The catching block shouldn't catch exceptions in itself, and a resignal should never run the block again...
>>
>> I'll try this in VAST.
>>
>>
>> Am 23.07.15 um 20:05 schrieb Norbert Hartl:
>>> You get a debugger at the position if the halt in the code. Meaning the exception block run more than once. And it would run forever.
>>>
>>> Norbert
>>>
>>>
>>>
>>>> Am 23.07.2015 um 18:46 schrieb Joachim Tuchel <[hidden email]>:
>>>>
>>>> Norbert,
>>>>
>>>> Sorry if this is a stupid question: what does the debugger say?
>>>>
>>>> I mean, assuming NotFound is an Exception, I'd expect a debugger showing a NotFound Error...
>>>>
>>>> Joachim
>>>>
>>>> Am 23.07.2015 18:34 schrieb Norbert Hartl <[hidden email]>:
>>>>>
>>>>>> Am 23.07.2015 um 17:54 schrieb Joachim Tuchel <[hidden email]>:
>>>>>>
>>>>>> Norbert,
>>>>>>
>>>>>> I'd say you get a NotFound Exception.
>>>>> In pharo you get a debugger. Meaning this piece of code is actively an endless loop.
>>>>>
>>>>> Norbert
>>>>>
>>>>>> Joachim
>>>>>>
>>>>>>
>>>>>>
>>>>>>> Am 23.07.2015 um 16:20 schrieb Norbert Hartl <[hidden email]>:
>>>>>>>
>>>>>>> What are the semantics of Exception>>#resignalAs: regarding active exception handler? Isn't the active exception handler excluded from being treated again? Taking the example
>>>>>>>
>>>>>>> | counter |
>>>>>>> counter := 0.
>>>>>>> [ 1/0 ]
>>>>>>>    on: Error
>>>>>>>    do: [ :e |
>>>>>>>        counter := counter + 1.
>>>>>>>        counter > 1 ifTrue: [ self halt ].
>>>>>>>        e resignalAs: NotFound new ].
>>>>>>>
>>>>>>> should it just run and end? Or should the debugger pop up?
>>>>>>>
>>>>>>> thanks,
>>>>>>>
>>>>>>> Norbert
>>>>>
>>>>>
>>
>>
>
>
> --
> -----------------------------------------------------------------------
> Objektfabrik Joachim Tuchel          mailto:[hidden email]
> 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
>
>