void try_throw_std_exception_from_error(std::error_code ec, const std::string &msg = std::string{})

This function saves writing boilerplate by throwing a standard library exception type equivalent to the supplied error code, with an optional custom message.

If the function returns, there is no standard library exception type equivalent to the supplied error code. The following codes produce the following exception throws:

EINVAL
std::invalid_argument
EDOM
std::domain_error
E2BIG
std::length_error
ERANGE
std::out_of_range
EOVERFLOW
std::overflow_error
ENOMEM
std::bad_alloc

The choice to refer to POSIX errno values above reflects the matching algorithm. As std::errc exactly maps POSIX errno, on all platforms std::generic_category error codes are matched by this function. Only on POSIX platforms only are std::system_category error codes also matched by this function.

Overridable: Not overridable.

Requires: C++ exceptions to be globally enabled.

Namespace: OUTCOME_V2_NAMESPACE

Header: <outcome/utils.hpp>