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
[Caml-list] assert caught by try with _
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2003-07-30 (05:45)
From: Jason Hickey <jyh@c...>
Subject: [Caml-list] unwind-protect
A related, but pragmatic problem.  Suppose we have some imperative code, 
and we need an "unwind-protect" operation.  Consider this code to make 
sure a file is closed after it is used.

let with_open_file (name : string) (f : in_channel -> unit) =
    let inc = open_in name in
          f inc;
          close inc
          exn ->
             close inc;
             raise exn

1. It would be wonderful to have a "finally" clause, so we don't have to 
duplicate the close operation.  I suppose we can fake it with CamlP4, 
but it seems better built-in.

2. This kind of exception re-raising does not work well with stack 
tracing (OCAMLRUNPARAM=b).  It would be very nice to add a "finally" 
clause that did not interfere with stack tracing, or make it so that 
re-raising would preserve the location where the exception was created.


Jason Hickey        
Caltech Computer Science      Tel: 626-395-6568 FAX: 626-792-4257

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: