Version française
Home     About     Download     Resources     Contact us    
Browse thread
Re: unwind-protect?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: David McClain <dmcclain@a...>
Subject: Re: unwind-protect?
>Is there an equivalent of Lisp's `unwind-protect' or Java's
>"try...finally"?

Here is the version that I use. It expects two functions of no arguments --
one for the protected portion and one for cleanup that is invoked in any
event.

let unwind_protect fn exitfn =
  let rslt =
    try
      fn()
    with
 exn ->
   ignore(exitfn());
   raise exn
  in
    ignore(exitfn());
    rslt


- D.McClain