From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id PAA24855; Thu, 19 Jul 2001 15:47:09 +0200 (MET DST) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id PAA24851 for ; Thu, 19 Jul 2001 15:47:09 +0200 (MET DST) Received: from pochi.inria.fr (pochi.inria.fr [128.93.8.128]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f6JDl8918461 for ; Thu, 19 Jul 2001 15:47:08 +0200 (MET DST) Received: (from mentre@localhost) by pochi.inria.fr (8.11.1/8.10.0) id f6JDl8h10984; Thu, 19 Jul 2001 15:47:08 +0200 X-Authentication-Warning: pochi.inria.fr: mentre set sender to David.Mentre@inria.fr using -f To: caml-list@inria.fr Subject: [Caml-list] Finding how and where an exception is raised From: David Mentre Date: 19 Jul 2001 15:47:08 +0200 Message-ID: User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.4 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hello, I would like to find how and where an exception is raised by printing a stack backtrace (something like Java Throwable.printStackTrace()). It seems to be impossible in plain ocaml. I could set the environment variable OCAMLRUNPARAM="b=1" and let the exception escape the program, but I would only get one exception. Right now, I'm using the 'assert false' trick[1]. However, I'm forced to put the assert at the place the test is done and I can't embed it in an inner function (something like in [2]). Has anybody a better solution? Best regards, d. [1] http://caml.inria.fr/archives/200010/msg00225.html [2] In the following program, the exception raised in meaningless (always in the check function): let check b = if b then (print_char '.'; flush stdout) else (print_char 'F'; flush stdout; assert(false)) let run () = check (true = true); check (true != false); check ("a" != "b") let _ = List.map ~f:(fun (s, f) -> try print_string s; f (); print_newline () with Assert_failure (filename, first, last) -> Printf.printf "\nCheck failed in file '%s', expression at characters %d-%d\n" filename first last; flush stdout) [ ("support", run) ] -- David.Mentre@inria.fr Opinions expressed here are only mine. ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr