Browse thread
[Caml-list] assert caught by try with _
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| 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
try
f inc;
close inc
with
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
--
Jason Hickey http://www.cs.caltech.edu/~jyh
Caltech Computer Science Tel: 626-395-6568 FAX: 626-792-4257
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners