error.h 876 B

123456789101112131415161718192021222324252627282930
  1. #ifndef ERROR_H
  2. #define ERROR_H
  3. #include <string>
  4. class Error
  5. {
  6. public:
  7. Error(const std::string& s, const char* t, int c=-255) : error(s), type(t), code(c){}
  8. virtual ~Error(){}
  9. std::string error;
  10. std::string type;
  11. int code;
  12. };
  13. #define DefineError(__Err__, __CODE__) class __Err__ : public Error{ public: __Err__(const std::string& e, const std::string& t) : Error(e, #__Err__, __CODE__){} ~__Err__(){} };
  14. DefineError(ArgumentCommandError, -1)
  15. DefineError(NoPadSelectedError, -2)
  16. DefineError(ParseError, -3)
  17. DefineError(LexerError, -4)
  18. DefineError(NotFoundError, -5)
  19. DefineError(MalformedError, -6)
  20. DefineError(MidiError, -7)
  21. DefineError(UnknownError, -8)
  22. DefineError(ResponseOK, 0)
  23. #define THROW(__ERR__, __MSG__) {std::ostringstream os; os << #__ERR__<< " : " << __MSG__ <<"\n"; std::cerr << os.str(); throw __ERR__(os.str(), #__ERR__);}
  24. #endif // ERROR_H