So far in this tutorial, type
result<T, EC> has always been a
std::error_code (though it can be of any type you wish instead).
in fact to merely satisfy
EC to be treated as if an
trait::has_error_code_v<EC> is true if there exists some ADL discovered free
std::error_code(i.e. EC might be
… or if
EC is implicitly convertible into a
Thus, we can in fact use any custom
EC type we like, including one carrying additional
information, or payload. This payload can carry anything you like, and you can tell
Outcome to do various things with that payload under various circumstances. For example:
result, throw a custom exception containing the cause of failure with accompanying context from the payload.
outcomefrom a payload carrying
result, set the exception ptr in the constructed
outcometo a custom exception containing the cause of the failure with accompanying context from the payload.
resultfrom library A being copy/moved into a namespace-localised
resultfrom C bindings library B, set the C
errnoif the error code and category map onto the
There are many, many other options of course. This tutorial can only cover a
reasonable subset. This section covers Example 1 above, throwing custom exceptions
with payload upon observation of an unsuccessful