Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Colin Walters <walters@c...>
Subject: unwind-protect?

Is there an equivalent of Lisp's `unwind-protect' or Java's
"try...finally"?  I wanted to write a function which changed to
another directory temporarily, and I came up with:

let in_directory d f =
  let olddir = Unix.getcwd() in
  (Unix.chdir d;
   Unix.chdir olddir)

But this won't work if f throws an exception.  Any suggestions?