You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

52 lines
1.3 KiB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
  1. #pragma once
  2. #include <exception>
  3. #include <string>
  4. namespace std _GLIBCXX_VISIBILITY(default) {
  5. class zexception : public exception {
  6. string m_ecodeinfo = "";
  7. int32_t m_ecode = 0;
  8. public:
  9. /** Takes a character string describing the error. */
  10. explicit zexception(int32_t ecode, const string& __arg) {
  11. m_ecodeinfo = __arg;
  12. m_ecode = ecode;
  13. }
  14. const char* what() const noexcept override { return m_ecodeinfo.c_str(); }
  15. int32_t ecode() const noexcept { return m_ecode; }
  16. };
  17. typedef enum {
  18. ke_ok = 10000 + 0,
  19. ke_error = 10000 + 1,
  20. ke_channel_is_close = 10000 + 2,
  21. ke_invalid_param = 10000 + 3,
  22. ke_invalid_packet_format = 10000 + 4,
  23. ke_overtime = 10000 + 5,
  24. ke_parse_config_file_fail = 10000 + 6,
  25. } zecode_t;
  26. static inline const char* zecode2str(zecode_t ecode) {
  27. switch (ecode) {
  28. case ke_ok:
  29. return "success";
  30. case ke_channel_is_close:
  31. return "channel_is_close";
  32. case ke_invalid_param:
  33. return "invalid_param";
  34. case ke_invalid_packet_format:
  35. return "invalid_packet_format";
  36. case ke_overtime:
  37. return "overtime";
  38. case ke_parse_config_file_fail:
  39. return "parse_config_file_fail";
  40. default:
  41. return "unkown error";
  42. }
  43. }
  44. } // namespace std _GLIBCXX_VISIBILITY(default)