Skip to content

Employ consistent error handling policy and make fatal error conditions fail fast #371

@dennisklein

Description

@dennisklein

Triggered by a discussion in the Alice WP3 mailing list about error handling, I propose to employ the following error handling "policy" (more in the sense of a guideline and less in the sense of a strict ruleset, simply to achieve more consistency over randomness) for FairMQ:

  1. State pre and postconditions via asserts / comments, violations are code bugs and need fixing, not exceptions
    • Apply throughout the current FairMQ codebase and collect and document practical examples
    • Decide whether to tie asserts to NDEBUG or a separate switch (gsl's runtime asserts are not disabable at all even for release builds)
  2. Prefer noexcept and strongly typed error codes via return channel - in the future: replace error codes with static exceptions
    • Study cases where a noexcept interface internally calls noexcept(false) interfaces and decide if the "Prefer noexcept" can hold as a guideline.
    • Study cases where we already use C-style int error codes that do not distinguish error codes from return value by type and decide whether it is worth changing them.
    • Decide for one of <system_error>, std::experimental::expected, Boost.Outcome or similar
    • Practical examples
  3. Throw only unrecoverable (that lead to a terminate) error condition from free and member functions (should basically boil down to std::bad_alloc and std::runtime_error("not implemented")).
    • Understand the consequences of a full stack unwind + automatic terminate vs early std::terminate, especially in combination with noexcept interfaces, with regard to debuggability
  4. Throw recoverable error conditions from ctors if class invariant cannot be established (to avoid 2-phase construction). Prefer to throw own exception types (possibly inheriting from a STL base exception type).
    • Practical examples

The above work-in-progress guidelines try to optimize for

  1. debuggability/maintainability and
  2. runtime performance (should really mainly be achieved via rule 1 and only on second order via rule 2).

Once the above points are finished:

Cc: @davidrohr, @ihrivnac, @ktf just FYI, this will take a bit to finish, but I guess we are not in a huge hurry here and it should not really block any activities in Alice O2 projects.

References:

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions