[
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: | David Mentre <David.Mentre@i...> |
| Subject: | [Caml-list] Finding how and where an exception is raised |
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