Skip to content

OCaml 5.0 & unhandled exceptions #11074

@dbuenzli

Description

@dbuenzli

While dabbing a bit into the future offering of OCaml 5, I got a bit confused on how unhandled exceptions are supposed to be handled among all the various threads of execution that became available.

One thing that surprised me is Domain.join raising the exception that may have been thrown by its Domain.spawn function. I thought the idea of domains was rather to be rare (in the sense one per core) "spawn and forget" like entities. Was the idea that domains would always periodically join their spawns ? But then I can only join one domain and it blocks !

So I would rather have expected each of them to have their own Printexc.set_uncaught_exception_handler initialized from the one set in the main domain. Unless I misunderstood something what we are looking at here is uncaught exceptions in domains going unnoticed (except for the main one) which I have to say is not an enticing perspective for long running programs.

It also seems that the Thread module now got its own Thread.set_uncaught_exception_handler. That's certainly a good addition since previously threads would simply ignore Printexc's one, but from the docs I couldn't understand if you have to set that per thread or if it uses the one you specified once for newly created threads.

Is there an actual design that I failed to see here ? From an end-user perspective I find all that quite confusing, are we going to need to set multiples places with uncaught exception handlers for long running programs ?

If you asked me it would be time to take the opportunity to define that Exn module we talked about during quite some time before it got closed without explanations and (if possible) centralize the reporting of uncaught exception with via a single handler that indicates in which context the uncaught exception occurred (bonus point if the context has room for user cases).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions