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.

45 lines
1.0 KiB

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 = 0,
  19. ke_channel_is_close = 1,
  20. ke_invalid_param = 2,
  21. ke_invalid_packet_format = 3,
  22. } zecode_t;
  23. static inline const char* zecode2str(zecode_t ecode) {
  24. switch (ecode) {
  25. case ke_ok:
  26. return "success";
  27. case ke_channel_is_close:
  28. return "channel_is_close";
  29. case ke_invalid_param:
  30. return "invalid_param";
  31. case ke_invalid_packet_format:
  32. return "invalid_packet_format";
  33. default:
  34. return "unkown error";
  35. }
  36. }
  37. } // namespace std _GLIBCXX_VISIBILITY(default)