I use Boost::Beast and i got somme exception message for exemple : resolve: No such host is known. I want in my code to print i message more significant that can a simple user get a idea what this message means . how i can do that?
that is the exemple that i chose to work with in the first but thy don't work for me
if (ec && ec != beast::errc::not_connected) {
beast::system_error{ ec };
std::cout << "beast::errc::not_connected" << ec << " with explanatory message " << ec.message() << std::endl;
}
if (ec && ec != beast::errc::no_buffer_space) {
beast::system_error{ ec };
std::cout << "beast::errc::no_buffer_space" << ec << " with explanatory message " << ec.message() << std::endl;
}
if (ec && ec != beast::errc::timed_out) {
beast::system_error{ ec };
std::cout << "beast::errc::timed_out" << ec << " with explanatory message " << ec.message() << std::endl;
}
if (ec && ec != beast::errc::no_buffer_space) {
beast::system_error{ ec };
std::cout << "beast::errc::no_buffer_space" << ec << " with explanatory message " << ec.message() << std::endl;
}
if (ec && ec != beast::errc::stream_timeout) {
beast::system_error{ ec };
std::cout << "beast::errc::stream_timeout" << ec << " with explanatory message " << ec.message() << std::endl;
}
As pointed out by others,
ec && ec != CODE
needed to beec && ec == CODE
.However, that conjunction is redundant:
ec && ec == CODE
is equivalent toec == CODE
(unless!ec.failed()
).I don't think any of the conditions are required:
That just prints the friendly message for any error:
Live On Coliru
Prints
To the gist of the question
There will not be friendlier error descriptions for "your users" as they will always depend on your program's logic and domain. So it's on the programmer to translate any non-recoverable errors into user-friendly conditions.
E.g. there cannot ever be a useful "end-user" description for
no_buffer_space
since ... you know buffers interest programmers only. You might translate that into something like "System load exceeded" or "Simulation too large" or "Attachment is too large".