commonDefine.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef COMMONDEFINE_H
  2. #define COMMONDEFINE_H
  3. #include "nlohmann/json.hpp"
  4. /*--------------------------------------------------------------------------
  5. * 公共宏定义
  6. *--------------------------------------------------------------------------*/
  7. #define nJson nlohmann::json
  8. /* nJson 异常处理的宏 */
  9. #define nJsonCatch catch(const nJson::parse_error& e) \
  10. { \
  11. SPDLOG_WARN("nJson parse failed: {}", e.what());\
  12. return false;\
  13. }\
  14. catch(const nJson::type_error& e) \
  15. {\
  16. SPDLOG_WARN("nJson type failed: {}", e.what());\
  17. return false;\
  18. }catch (const std::exception& e)\
  19. {\
  20. SPDLOG_WARN("nJson std failed: {}", e.what());\
  21. return false;\
  22. }catch(...)\
  23. {\
  24. SPDLOG_WARN("nJson Operated failed: unknown error");\
  25. return false;\
  26. }
  27. /* nJson 异常处理的宏,不带返回值 */
  28. #define nJsonCatchNoReturn catch(const nJson::parse_error& e) \
  29. { \
  30. SPDLOG_WARN("nJson parse failed: {}", e.what());\
  31. return;\
  32. }\
  33. catch(const nJson::type_error& e) \
  34. {\
  35. SPDLOG_WARN("nJson type failed: {}", e.what());\
  36. return;\
  37. }catch (const std::exception& e)\
  38. {\
  39. SPDLOG_WARN("nJson std failed: {}", e.what());\
  40. return;\
  41. }catch(...)\
  42. {\
  43. SPDLOG_WARN("nJson Operated failed: unknown error");\
  44. return;\
  45. }
  46. #endif /* COMMONDEFINE_H */