Hi, I recently published a blog post proposing a solution to the backtrace problem of Ocaml. It includes a Camlp4 filter and a small Ocaml library to handle exception backtraces. The performance drawback is negligible when backtraces are not activated, and reasonable when they are. You can read about it here : http://gallium.inria.fr/blog/a-library-to-record-ocaml-backtraces/ -- JH Jourdan Le 11/04/2013 00:16, Chet Murthy a écrit : > > People have previously asked about try...finally support in Ocaml, and > it's been observed (correctly) that you can write a little combinator > to give you this support, e.g. > > let finally f arg finf = > let rv = try Inl(f arg) with e -> > Inr e > in (try finf arg rv with e -> ()); > match rv with > Inl v -> v > | Inr e -> raise e > > The problem is, you discard stack-traceback when you rethrow the > exception. One can program around this explicitly by capturing the > backtrace string and appending it to the rethrown exception, but it's > cumbersome and won't work for exceptions like Not_found that are > already defined without a mutable string slot. > > It sure would be nice of ocaml had try...finally that preserved the > traceback information properly .... though maybe it isn't possible. > Certainly in the case where the finally block doesn't raise any > exceptions itself (even those that are caught silently), it seems like > it ought to be possible. > > In an unrelated but similar sense, when programming with threads in > ocaml, it's easy (easy!) to deadlock your program. Now, I've been > writing Java programs for years, and so am aware of how careful one > must be, and I'm writing my code using a single mutex protecting the > critical section. But I forgot and didn't mutex-protect one method -- > what merely printed out the contents of a shared daa-structure, and > when that printout coincided with a thread actually mutating the > data-structure, I got a deadlock. Not hard to track down, and I > chided myself for being lax. > > But the thing is, in Java (blecch!) I would have been able to use the > "javacore" facility to get a full-thread stack-traceback, and could > have used that to get a good idea of where my deadlock was. > > I'm not saying that this is something ocaml should have, but I figured > I'd ask: are others (who use threads in ocaml) wishing for something > like this? > > --chet-- > > >