There is very little information on the Internet regarding std :: throw_with_nested and C ++, and how to use it. I am currently implementing it in all of my code, but is this a bad practice or is everything alright? Or should I do it somehow differently? I would like to hear the opinions of others on this subject, thanks. I apologize if there is another topic on this issue, but I could only find very little. The following is an example of my code:
void GkCrypto::Crypto::generateRandomBytes(unsigned char *buf)
{
try {
if (1 != RAND_bytes(buf, sizeof(buf))) {
handleErrors();
}
} catch (const std::exception &e) {
std::throw_with_nested(std::runtime_error(e.what()));
}
}
void GkCrypto::Crypto::handleErrors()
{
unsigned long errCode;
std::cerr << gettext("An error has occured!") << std::endl;
while (errCode = ERR_get_error()) {
char *err = ERR_error_string(errCode, NULL);
std::cerr << err << std::endl;
char *errBuf = NULL;
std::sprintf(errBuf, gettext("An error has occured! Error:\n\n %s\n"), err);
throw std::runtime_error(errBuf);
}
abort();
}
source
share