Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0004477OCaml~DO NOT USE (was: OCaml general)public2008-01-11 16:522011-05-29 12:20
Assigned Toxclerc 
PlatformOSOS Version
Product Version3.10.0 
Target VersionFixed in Version3.11.2+dev 
Summary0004477: Feature wish: custom exception printers
DescriptionWhile we are at exceptions. It would be great if it were possible to define custom exception printers for the cases Printexc cannot handle automatically.

val register_printer : string -> (exn -> string) -> unit

This function is called with the name of the exception and the printing function. It is ensured by the runtime that the function is only called with the right exceptions, so a typical definition could be:

    | Foo.Foo(arg1,arg2) ->
         "Foo.Foo(" ^ arg1_to_string arg1 ^ "," ^ arg2_to_string arg2 ^ ")"
    | _ ->
         assert false

It is allowed to recursively call Printexc.to_string from within the printer.

I'm quite sure somebody will then come up with a camlp4 extension generating these definitions.
Additional InformationThe motivation for this enhancement is that we are currently developing server components, and exceptions simply happen as part of normal operations. Usually they are handled by printing them to a log file, and then terminating the current action.

Currently, we work around by defining our own custom printers as normal O'Caml functions. But these work only for a specific context, e.g. we have Hydro_util.exn_to_string for all exceptions coming from Hydro (Wink's ICE implementation), and Pxp_types.string_of_exn for all exceptions coming from PXP, and a few other. Mixing these printers so they work for all relevant contexts is cumbersome.

Furthermore, we have the problem in server platforms like Hydro that we need to print exceptions that come from anywhere, e.g. because they are caught from an invocation of a user function. One can again work around by allowing to plug in custom printers, but this feels also a bit strange.

My thinking is that the O'Caml runtime is the right place for aggregating these functions.
TagsNo tags attached.
Attached Files

- Relationships
duplicate of 0000123closedxclerc Pretty printer pour exceptions 

-  Notes
gerd (reporter)
2008-09-01 01:49

I've implemented this idea in ocamlnet, module Netexn: [^] [^]

The registry uses the name of the exception as key to a hash table (as an accelerator for lookups), and the reference to the exception definition block in an assoc list within that table. This block can be moved around by the GC, and cannot serve directly as hash key.

It is possible to define recursive printers for exception like

exception E of exn

but no provisions are taken for detecting cycles in the value graph.
xclerc (reporter)
2009-09-16 15:35

support for custom exception printers has been committed in the 'release311' branch.

- Issue History
Date Modified Username Field Change
2008-01-11 16:52 gerd New Issue
2008-01-18 15:36 doligez Status new => acknowledged
2008-09-01 01:49 gerd Note Added: 0004594
2009-08-20 13:20 xclerc Relationship added duplicate of 0000123
2009-09-16 15:35 xclerc Note Added: 0005103
2009-09-16 15:35 xclerc Status acknowledged => resolved
2009-09-16 15:35 xclerc Fixed in Version => 3.11.2+dev
2009-09-16 15:35 xclerc Resolution open => fixed
2009-09-16 15:35 xclerc Assigned To => xclerc
2011-05-29 12:20 xleroy Status resolved => closed
2017-02-23 16:36 doligez Category OCaml general => -OCaml general
2017-03-03 17:55 doligez Category -OCaml general => -(deprecated) general
2017-03-03 18:01 doligez Category -(deprecated) general => ~deprecated (was: OCaml general)
2017-03-06 17:04 doligez Category ~deprecated (was: OCaml general) => ~DO NOT USE (was: OCaml general)

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker