SpCatch.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #ifndef _RVC_CATCH_H__
  2. #define _RVC_CATCH_H__
  3. #pragma once
  4. #include <exception>
  5. #include <stdexcept>
  6. #include <cstring>
  7. #include <iostream>
  8. #include "SpComm.hpp"
  9. /** we should integrate it with SpBase.h at the future*/
  10. #define SPCATCH_NOT_IMPLEMENTED throw ::SP::Catch::NotImplementedException( SP_INTERNAL_LINEINFO )
  11. namespace SP {
  12. namespace Catch {
  13. class CBaseException : public std::exception
  14. {
  15. public:
  16. CBaseException(const ErrorCodeEnum& ec, ::SP::Detail::SourceLineInfo const& lineInfo)
  17. :m_errorCode(ec),m_lineInfo(lineInfo)
  18. {
  19. std::ostringstream oss;
  20. oss << m_lineInfo << " occurs: " << SpStrError(m_errorCode);
  21. m_what = oss.str().c_str();
  22. }
  23. CBaseException(::SP::Detail::SourceLineInfo const& lineInfo)
  24. :CBaseException(Error_Exception, lineInfo) {}
  25. virtual ~CBaseException() noexcept {}
  26. virtual const char* what() const noexcept
  27. {
  28. return m_what;
  29. }
  30. protected:
  31. ErrorCodeEnum m_errorCode;
  32. ::SP::Detail::SourceLineInfo m_lineInfo;
  33. CSimpleStringA m_what;
  34. };
  35. class NotImplementedException : public CBaseException
  36. {
  37. public:
  38. NotImplementedException(::SP::Detail::SourceLineInfo const& lineInfo)
  39. :CBaseException(Error_NotImpl, lineInfo)
  40. {
  41. }
  42. };
  43. class CBaseRTException : public std::runtime_error
  44. {
  45. public:
  46. CBaseRTException(const char* msg) :std::runtime_error(msg)
  47. {}
  48. CBaseRTException() = default;
  49. ~CBaseRTException() = default;
  50. };
  51. }
  52. }
  53. #endif /** _RVC_CATCH_H__*/