From: David Mentre <David.Mentre@inria.fr>
To: caml-list@inria.fr
Subject: [Caml-list] Finding how and where an exception is raised
Date: 19 Jul 2001 15:47:08 +0200 [thread overview]
Message-ID: <qtln161115v.fsf@pochi.inria.fr> (raw)
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
next reply other threads:[~2001-07-19 13:47 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-07-19 13:47 David Mentre [this message]
2001-07-27 8:21 ` Xavier Leroy
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=qtln161115v.fsf@pochi.inria.fr \
--to=david.mentre@inria.fr \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox