Bitcoin Core 28.99.0
P2P Digital Currency
|
The util::Result class provides a standard way for functions to return either error messages or result values.
The util::Result class provides a standard way for functions to return either error messages or result values.It is intended for high-level functions that need to report error strings to end users. Lower-level functions that don't need this error-reporting and only need error-handling should avoid util::Result and instead use standard classes like std::optional, std::variant, and std::tuple, or custom structs and enum types to return function results.
Usage examples can be found in, but in general code returning util::Result<T>
values is very similar to code returning std::optional<T>
values. Existing functions returning std::optional<T>
can be updated to return util::Result<T>
and return error strings usually just replacing return std::nullopt;
with return util::Error{error_string};
.