|Anonymous | Login | Signup for a new account||2019-02-24 01:40 CET|
|Main | My View | View Issues | Change Log | Roadmap|
|View Issue Details|
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0006619||OCaml||documentation||public||2014-10-19 21:34||2016-12-07 11:36|
|Target Version||Fixed in Version||4.02.2+dev / +rc1|
|Summary||0006619: Documentation for Printexc.register_uncaught_exception_handler could be improved|
|Description||Currently, we have:|
Printexc.set_uncaught_exception_handler fn registers fn as the handler for uncaught exceptions. The default handler prints the exception and backtrace on standard error output.
Note that when fn is called all the functions registered with at_exit have already been called. Because of this you must make sure any output channel fn writes on is flushed.
If fn raises an exception, it is ignored.
Following discussion on caml-list, I would suggest the final paragraph be replaced by something like:
"If an exception is raised inside the handler fn and remains uncaught, neither the default handler nor fn is called: the exception is ignored."
|Tags||No tags attached.|
|Actually if [fn] raises an exception, the current code will print the original exception and backtrace and then the exception raised by [fn] with its backtrace.|
Right, so if I have:
let f _ _ = raise Not_found
let _ = Printexc.set_uncaught_exception_handler f
let _ = failwith "foo"
feast:~ john$ ./a.out
Fatal error: exception Failure("foo")
Fatal error in uncaught exception handler: exception Not_found
This seems like reasonable behaviour.
It doesn't work in the top level, though -- should it?:
OCaml version 4.02.1
# let f _ _ = raise Not_found;;
val f : 'a -> 'b -> 'c = <fun>
# let _ = Printexc.set_uncaught_exception_handler f;;
- : unit = ()
# let _ = failwith "foo";;
Exception: Failure "foo".
> It doesn't work in the top level, though -- should it?
The exception is not uncaught, it is caught by the toplevel.
So, for the doc, how about this:
"If [fn] raises an exception, both the exceptions passed to [fn] and raised by [fn] will be printed with their respective backtraces."
> The exception is not uncaught, it is caught by the toplevel.
So in the example above, "Exception: Failure "foo" is printed by the top level, not by the default uncaught exception handler?
> "If [fn] raises an exception, both the exceptions passed to [fn] and raised by [fn] will be printed with their respective backtraces."
> So in the example above, "Exception: Failure "foo" is printed by the top level, not by the default uncaught exception handler?
Yes. I guess it could make sense to pass these exceptions to the uncaught exception handler.
In the meantime I'll add a comment about it.
|As a side note, you can overwrite [Toploop.print_out_phrase] to get these exceptions.|
edited on: 2014-10-20 15:22
I commited a patch in trunk: 15560, and 4.02: 15561.
|2014-10-19 21:34||johnwhitington||New Issue|
|2014-10-20 00:38||dim||Note Added: 0012396|
|2014-10-20 14:00||johnwhitington||Note Added: 0012400|
|2014-10-20 14:38||dim||Note Added: 0012401|
|2014-10-20 14:42||dim||Note Added: 0012402|
|2014-10-20 14:49||johnwhitington||Note Added: 0012403|
|2014-10-20 15:08||dim||Note Added: 0012404|
|2014-10-20 15:09||dim||Note Added: 0012405|
|2014-10-20 15:19||dim||Note Added: 0012406|
|2014-10-20 15:19||dim||Assigned To||=> dim|
|2014-10-20 15:19||dim||Status||new => assigned|
|2014-10-20 15:21||dim||Status||assigned => resolved|
|2014-10-20 15:21||dim||Fixed in Version||=> 4.02.2+dev / +rc1|
|2014-10-20 15:21||dim||Resolution||open => fixed|
|2014-10-20 15:22||dim||Note Edited: 0012406||View Revisions|
|2016-12-07 11:36||xleroy||Status||resolved => closed|
|2017-02-23 16:35||doligez||Category||OCaml documentation => Documentation|
|2017-02-23 16:44||doligez||Category||Documentation => documentation|
|Copyright © 2000 - 2011 MantisBT Group|