Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006619OCamldocumentationpublic2014-10-19 21:342016-12-07 11:36
Reporterjohnwhitington 
Assigned Todim 
PrioritynormalSeveritytextReproducibilityN/A
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version4.02.2+dev / +rc1 
Summary0006619: Documentation for Printexc.register_uncaught_exception_handler could be improved
DescriptionCurrently, 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."

TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0012396)
dim (developer)
2014-10-20 00:38

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.
(0012400)
johnwhitington (reporter)
2014-10-20 14:00

Right, so if I have:

let f _ _ = raise Not_found

let _ = Printexc.set_uncaught_exception_handler f

let _ = failwith "foo"

I get

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".
(0012401)
dim (developer)
2014-10-20 14:38

> It doesn't work in the top level, though -- should it?

The exception is not uncaught, it is caught by the toplevel.
(0012402)
dim (developer)
2014-10-20 14:42

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."
(0012403)
johnwhitington (reporter)
2014-10-20 14:49

> 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."

Looks good.
(0012404)
dim (developer)
2014-10-20 15:08

> 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.
(0012405)
dim (developer)
2014-10-20 15:09

As a side note, you can overwrite [Toploop.print_out_phrase] to get these exceptions.
(0012406)
dim (developer)
2014-10-20 15:19
edited on: 2014-10-20 15:22

I commited a patch in trunk: 15560, and 4.02: 15561.


- Issue History
Date Modified Username Field Change
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
Powered by Mantis Bugtracker