SpanReport
is an error-report type containing a reference to an error-string stating the cause of the error from the error type of a Result<T, E>
.
- When the error types contain the string description of the errors themselves and you can get a reference to the error.
TIP: SpanReport
is named after std::span
as it is only a type-erased reference-view of the error string.
Constructing a SpanReport
for your error type
NOTE: character literals (i.e. "A STRING"
) have static storage duration and live throughout the program, constructing a SpanReport
with them just forwards a reference to them, it is safe to do this)
namespace net{
enum class Error {
ConnectionError,
ServerClosed,
ServerUnreachable
};
};
switch(err){
case net::Error::ConnectionError:
case net::Error::ServerClosed:
case net::Error::ServerUnreachable:
}
}
namespace net{
class Error {
std::string
const &
what() const noexcept;
std::string_view better_what() const noexcept;
std::string_view const& best_what() const noexcept;
query
std::string dangerous_what() const noexcept;
};
};
SpanReport operator>>(ReportQuery, net::Error const& err) noexcept {
}
Exception-safety
Ensure to not throw exceptions.