Skip to content
Snippets Groups Projects

Resolve "Fix incorrect type in Errnum class"

Merged Michael Davis requested to merge 584-fix-incorrect-type-in-errnum-class into main
Files
12
+ 18
39
@@ -18,54 +18,33 @@
#include "common/exception/Errnum.hpp"
#include "common/utils/utils.hpp"
#include <errno.h>
#include <string.h>
namespace cta::exception {
using namespace cta::exception;
Errnum::Errnum(std::string what):Exception("") {
m_errnum = errno;
ErrnumConstructorBottomHalf(what);
Errnum::Errnum(int err, std::string_view what) : Exception(),
m_errnum(err),
m_strerror(utils::errnoToString(err)) {
std::stringstream whatWithErrnum;
whatWithErrnum << what << (what.empty() ? "" : " ")
<< "Errno=" << m_errnum << ": " << m_strerror;
getMessage() << whatWithErrnum.str();
}
Errnum::Errnum(int err, std::string what):Exception("") {
m_errnum = err;
ErrnumConstructorBottomHalf(what);
}
Errnum::Errnum(std::string_view what) : Errnum(errno, what) { }
void Errnum::ErrnumConstructorBottomHalf(const std::string & what) {
m_strerror = utils::errnoToString(m_errnum);
std::stringstream w2;
if (what.size())
w2 << what << " ";
w2 << "Errno=" << m_errnum << ": " << m_strerror;
getMessage() << w2.str();
void Errnum::throwOnReturnedErrno(int err, std::string_view context) {
if(err) throw Errnum(err, context);
}
void Errnum::throwOnReturnedErrno (const int err, const std::string &context) {
if (err) throw Errnum(err, context);
void Errnum::throwOnNonZero(int status, std::string_view context) {
if(status) throw Errnum(context);
}
void Errnum::throwOnNonZero(const int status, const std::string &context) {
if (status) throw Errnum(context);
void Errnum::throwOnNull(const void* const ptr, std::string_view context) {
if(nullptr == ptr) throw Errnum(context);
}
void Errnum::throwOnZero(const int status, const std::string &context) {
if (!status) throw Errnum(context);
void Errnum::throwOnMinusOne(ssize_t ret, std::string_view context) {
if(ret == -1) throw Errnum(context);
}
void Errnum::throwOnNull(const void *const f, const std::string &context) {
if (nullptr == f) throw Errnum(context);
}
void Errnum::throwOnNegative(const int ret, const std::string &context) {
if (ret < 0) throw Errnum(context);
}
void Errnum::throwOnMinusOne(const int ret, const std::string &context) {
if (-1 == ret) throw Errnum(context);
}
void Errnum::throwOnNegativeErrnoIfNegative(const int ret, const std::string& context) {
if (ret < 0) throw Errnum(-ret, context);
}
} // namespace cta::exception
Loading