Unwind-protectTests

Quick Links

Tests That Should Work

GO out of Protected Form

(tagbody
   (unwind-protect
      (go out)
      (print 'DoesNotSkip)
   )
   out
   (print 'End)
)

=>
DOESNOTSKIP 
END 
NIL

THROW out of Protected Form

(tagbody
   (catch 'a
      (unwind-protect
         (throw 'a 1)
         (print 'DoesNotSkip)
      )
      (print 'X-Skipped)
   )
   (print 'End)
)

=>
DOESNOTSKIP 
END 
NIL

THROW out of Protected Form; GO out of Cleanup Form to end

(catch 'a
   (block b
      (tagbody
         (print 'Before_Unwind_Protect)
         (unwind-protect 
            (progn (print 'Before_Catch)
               (catch 'c 
                  (print 'Before_Throw)
                  (go end)
                  (print 'X-After_Throw)
               )
            )
            (progn (print 'Unprotected_CleanUp)
               (throw 'a 'ThrowA_In_Cleanup_Form)
               (print 'X-After_Go_End)
            )
         )
         (print 'X-After_Unwind_Protect)
         end
         (print 'End_Of_Tagbody)
         (go EndTwo)
         endTwo
         (print 'Second_End_Label)
      )
   )
)

=>
BEFORE_UNWIND_PROTECT 
BEFORE_CATCH 
BEFORE_THROW 
UNPROTECTED_CLEANUP 
END_OF_TAGBODY 
SECOND_END_LABEL 
NIL

Tests That Should Not Work

GO from Cleanup Form to Protected Form

Attempts to go from the cleanup form into the protected form

(tagbody
   (print 'Before_Unwind_Protect)
   (unwind-protect 
      (progn (print 'Before_Catch)
         (catch 'c 
            (print 'Before_Throw)
            (throw 'a 'X-Thrown_Value)
            (print 'X-After_Throw)
            INSIDE
            (print 'X-After_Inside)
         )
      )
      (progn (print 'Unprotected_CleanUp)
         (go INSIDE)
         (print 'X-After_Go_Inside)
      )
   )
   (print 'X-After_Unwind_Protect)
)

=>
BEFORE_UNWIND_PROTECT 
BEFORE_CATCH 
BEFORE_THROW 
Error: Uncaught throw of X-THROWN_VALUE to A.
Topic revision: r6 - 2007-03-31 - 12:59:24 - CharlesShapiro
 
Home
This site is powered by the TWiki collaboration platformCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback