Currently Err.value() returns exactly what I wrote on the line above: ErrorKind::SomeError.
In the other case with leaf::match<MyErrorType, ErrorKind::SomeError, ErrorKind::MoreError> Err), Err.value() returns whichever of ErrorKind::SomeError or ErrorKind::MoreError actually matched.
In all cases, the actual error object is not accessible. As I am matching on the type of the error object, I am aware of the MyErrorType itself and it is probably public API and I can know the members of it. That means I can use Err.value().value to access what is currently available as Err.value but I can also Err.value().Payload to access the payload in the above case.
There is no loss of functionality by making the error instance available in error handlers. There is a gain in functionality.
This is true for any error type. I encountered it with std::error_code because I needed to access the message of the error_code. If match<E, V...>::value() returned the std::error_code itself, I could write:
match<E, V...>::value()
currently returns the matches value, which I wrote in my lambda, but it should return the error object which matched.Consider https://godbolt.org/z/it5qjZ
We have
and
Currently
Err.value()
returns exactly what I wrote on the line above:ErrorKind::SomeError
.In the other case with
leaf::match<MyErrorType, ErrorKind::SomeError, ErrorKind::MoreError> Err)
,Err.value()
returns whichever ofErrorKind::SomeError
orErrorKind::MoreError
actually matched.In all cases, the actual error object is not accessible. As I am matching on the type of the error object, I am aware of the MyErrorType itself and it is probably public API and I can know the members of it. That means I can use
Err.value().value
to access what is currently available asErr.value
but I can alsoErr.value().Payload
to access the payload in the above case.There is no loss of functionality by making the error instance available in error handlers. There is a gain in functionality.
This is true for any error type. I encountered it with
std::error_code
because I needed to access themessage
of theerror_code
. Ifmatch<E, V...>::value()
returned thestd::error_code
itself, I could write:As it is
err.value()
returns meFileResult::FileNotFound
. It is not useful for the framework to tell me what I just told it.