caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Finding how and where an exception is raised
@ 2001-07-19 13:47 David Mentre
  2001-07-27  8:21 ` Xavier Leroy
  0 siblings, 1 reply; 2+ messages in thread
From: David Mentre @ 2001-07-19 13:47 UTC (permalink / raw)
  To: caml-list

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


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] Finding how and where an exception is raised
  2001-07-19 13:47 [Caml-list] Finding how and where an exception is raised David Mentre
@ 2001-07-27  8:21 ` Xavier Leroy
  0 siblings, 0 replies; 2+ messages in thread
From: Xavier Leroy @ 2001-07-27  8:21 UTC (permalink / raw)
  To: David Mentre; +Cc: caml-list

> 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.  I think the "stack backtrace" mechanism of OCaml could be
extended to provide what you need.  I'll look into this after 3.02 is
out.

Best wishes,

- Xavier Leroy
-------------------
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


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2001-07-27  8:22 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-07-19 13:47 [Caml-list] Finding how and where an exception is raised David Mentre
2001-07-27  8:21 ` Xavier Leroy

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).