forstio/source/error.cpp

28 lines
762 B
C++
Raw Normal View History

2020-07-28 01:23:38 +02:00
#include "error.h"
namespace gin {
2020-08-09 02:03:09 +02:00
Error::Error() : error_{0} {}
2020-08-09 02:04:48 +02:00
Error::Error(const std::string &msg) : error_message{msg}, error_{1} {}
2020-08-09 02:03:09 +02:00
2020-08-09 02:04:48 +02:00
Error::Error(const std::string &msg, int8_t code)
: error_message{msg}, error_{code} {}
2020-08-09 02:03:09 +02:00
2020-08-09 02:04:48 +02:00
Error::Error(const Error &error)
: error_message{error.error_message}, error_{error.error_} {}
2020-08-09 02:03:09 +02:00
2020-08-09 02:04:48 +02:00
const std::string &Error::message() const { return error_message; }
2020-08-09 02:03:09 +02:00
bool Error::failed() const { return error_ != 0; }
bool Error::isCritical() const { return error_ < 0; }
bool Error::isRecoverable() const { return error_ > 0; }
2020-08-09 02:04:48 +02:00
Error criticalError(const std::string &msg) { return Error{msg, -1}; }
2020-08-09 02:03:09 +02:00
2020-08-09 02:04:48 +02:00
Error recoverableError(const std::string &msg) { return Error{msg, 1}; }
2020-08-09 02:03:09 +02:00
Error noError() { return Error{}; }
2020-08-09 02:04:48 +02:00
} // namespace gin