|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- #ifndef MNR_faults
- #define MNR_faults
-
- #include <stdexcept>
- #include <cstdlib>
- #include <iostream>
- #include <string>
-
- using namespace std;
-
- const int DefaultExitCode = EXIT_FAILURE;
-
- class AbortCheck {
-
- private:
-
- const string myDescription;
-
- public:
-
- AbortCheck(const string& Text) : myDescription(Text) {}
-
- void operator()(bool X) const {
- if(false == X) {
- cerr << myDescription << endl;
- abort();
- }
- }
-
- const string Description() { return myDescription; }
- };
-
- class AbortFault {
-
- private:
-
- const string myDescription;
-
- public:
-
- AbortFault(const string& Text) : myDescription(Text) {}
-
- void operator()(bool X) const {
- if(true == X) {
- cerr << myDescription << endl;
- abort();
- }
- }
-
- const string Description() const { return myDescription; }
- };
-
- class ExitCheck {
-
- private:
-
- const string myDescription;
- const int myExitCode;
-
- public:
-
- ExitCheck(const string& Text, int Code=DefaultExitCode) :
- myDescription(Text), myExitCode(Code) {}
-
- void operator()(bool X) const {
- if(false == X) {
- cerr << myDescription << endl;
- exit(myExitCode);
- }
- }
-
- const string Description() { return myDescription; }
- const int ExitCode() { return myExitCode; }
- };
-
- class ExitFault {
-
- private:
-
- const string myDescription;
- const int myExitCode;
-
- public:
-
- ExitFault(const string& Text, int Code=DefaultExitCode) :
- myDescription(Text), myExitCode(Code) {}
-
- void operator()(bool X) const {
- if(true == X) {
- cerr << myDescription << endl;
- exit(myExitCode);
- }
- }
-
- const string Description() const { return myDescription; }
- const int ExitCode() const { return myExitCode; }
- };
-
- class RuntimeCheck : public runtime_error {
-
- public:
-
- RuntimeCheck(const string& Text) : runtime_error(Text) {}
-
- void operator()(bool X) const {
- if(false == X) {
- throw *this;
- }
- }
- };
-
- class RuntimeFault : public runtime_error {
-
- public:
-
- RuntimeFault(const string& Text) : runtime_error(Text) {}
-
- void operator()(bool X) const {
- if(true == X) {
- throw *this;
- }
- }
- };
-
- class LogicCheck : public logic_error {
-
- public:
-
- LogicCheck(const string& Text) : logic_error(Text) {}
-
- void operator()(bool X) const {
- if(false == X) {
- throw *this;
- }
- }
- };
-
- class LogicFault : public logic_error {
-
- public:
-
- LogicFault(const string& Text) : logic_error(Text) {}
-
- void operator()(bool X) const {
- if(true == X) {
- throw *this;
- }
- }
- };
-
- #endif
-
-
|