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] Exceptions and at_exit
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: David Fox <>
Subject: Re: [Caml-list] Exceptions and at_exit
David Fox <> writes:

> I have some at_exit functions that must execute before my program
> exits, but I also want to see a traceback of any exception that
> occurs.  Can I catch the exception, print a traceback like the one you
> get when you exit and then call exit?  Or can I catch the exception,
> execute the at_exit functions, and then re-raise the exception?  How
> *do* you re-raise an exception, anyway?  Do you just catch the
> exception and raise it?

My confusion about re-raising exceptions was caused by the fact that
you get different behavior if you say something like

  try ... with
    Failure msg -> <do some stuff>; raise (Failure msg)

vs something like

  try ... with
    exn ->
       begin match exn with Failure msg -> <do some stuff> end;
       raise exn

In the second case, you are re-raising the exception, in the first
you are raising a new exception and your original traceback is lost.
To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: