[vwnc] Problem with #ensure blocks not being evaluated

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

[vwnc] Problem with #ensure blocks not being evaluated

Mark Plas

Hi,

 

I have a problem with ensure: blocks not being evaluated. If I run this example:

 

 

 

[

                [[[Object errorSignal raise] ensure:

                                               [Transcript

                                                               cr;

                                                               show: 'hop']]

                               on: Object errorSignal

                               do:

                                               [:ex |

                                               ex isNested.

                                               ex pass]]

                                               ensure:

                                                               [Transcript

                                                                              cr;

                                                                              show: 'hop2']]

                                               on: Object errorSignal

                                               do:

                                                               [:ex |

                                                               Transcript

                                                                              cr;

                                                                              show: 'Ex']

 

 

It shows this on the transcript:

 

                Ex

hop2

 

As you can see 'hop' is not shown which means that the first #ensure: block hasn't been evaluated. This happens because I'm sending #isNested to the exception. Here's the implementation of isNested:

 

GenericException>>isNested

                "Determine whether the current exception handler is within the scope of another

                handler for the same exception."

 

               

                handlerContext == nil                   "shouldn't be- unless called from #defaultAction"

                               ifTrue: [ ^false ].

                ^[(self findHandlerContextFrom: handlerContext sender markDebug: false) ~~ nil]

                               ensure: [firstUnwindContext := nil]

 

 

As you can see in the last line, the firstUnwindContext is being set to nil. This is probably done because this variable is being modified in the #findHandlerContextFrom:markDebug: method. If you want to know the exact reason why things go wrong, you'll have to trace through the example code. I have a suggestion for a fix:

 

isNested

                "Determine whether the current exception handler is within the scope of another

                handler for the same exception."

 

                | old |

                handlerContext == nil                   "shouldn't be- unless called from #defaultAction"

                               ifTrue: [ ^false ].

 

                old := firstUnwindContext.

                ^[(self findHandlerContextFrom: handlerContext sender markDebug: false) ~~ nil]

                               ensure: [firstUnwindContext := old]

 

Instead of setting the firstUnwindContext to nil I set it to the value it had at the beginning of the method.

 

Do you think this is a valid fix?

 

Thanks,

Mark


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc