123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- #ifndef _RVC_CATCH_H__
- #define _RVC_CATCH_H__
- #pragma once
- #include <exception>
- #include <stdexcept>
- #include <cstring>
- #include <iostream>
- #include "SpComm.hpp"
- /** we should integrate it with SpBase.h at the future*/
- #define SPCATCH_NOT_IMPLEMENTED throw ::SP::Catch::NotImplementedException( SP_INTERNAL_LINEINFO )
- namespace SP {
- namespace Detail
- {
- struct SourceLineInfo {
- SourceLineInfo() :file(""), line(0) {/*empty*/ }
- SourceLineInfo(char const* file, std::size_t line) :file(file), line(line) {/*empty*/ }
- #if defined(_MSC_VER)
- #else
- SourceLineInfo(SourceLineInfo const& rhs) = default;
- SourceLineInfo(SourceLineInfo&& rhs) = default;
- SourceLineInfo& operator = (SourceLineInfo const& rhs) = default;
- SourceLineInfo& operator =(SourceLineInfo&& rhs) = default;
- #endif //_MSC_VER
- bool operator == (SourceLineInfo const& rhs) const {
- return line < rhs.line || (line == rhs.line && (std::strcmp(file, rhs.file) < 0));
- }
- bool operator < (SourceLineInfo const& rhs) const {
- return line == rhs.line && (file == rhs.file || std::strcmp(file, rhs.file) == 0);
- }
- const std::string ToString() const {
- std::ostringstream oss;
- oss << "file: {" << _GetFileName(file) << "} ,line: {" << line << "}";
- return oss.str();
- }
- char const* file;
- std::size_t line;
- };
- inline std::ostream& operator << (std::ostream& os, SourceLineInfo const& info)
- {
- os << info.file << '(' << info.line << ')';
- return os;
- }
- }
- namespace Catch {
- class CBaseException : public std::exception
- {
- public:
- CBaseException(const ErrorCodeEnum& ec, ::SP::Detail::SourceLineInfo const& lineInfo)
- :m_errorCode(ec),m_lineInfo(lineInfo)
- {
- std::ostringstream oss;
- oss << m_lineInfo << " occurs: " << SpStrError(m_errorCode);
- m_what = oss.str().c_str();
- }
- CBaseException(::SP::Detail::SourceLineInfo const& lineInfo)
- :CBaseException(Error_Exception, lineInfo) {}
- virtual ~CBaseException() noexcept {}
- virtual const char* what() const noexcept
- {
- return m_what;
- }
- protected:
- ErrorCodeEnum m_errorCode;
- ::SP::Detail::SourceLineInfo m_lineInfo;
- CSimpleStringA m_what;
- };
- class NotImplementedException : public CBaseException
- {
- public:
- NotImplementedException(::SP::Detail::SourceLineInfo const& lineInfo)
- :CBaseException(Error_NotImpl, lineInfo)
- {
- }
- };
- class CBaseRTException : public std::runtime_error
- {
- public:
- CBaseRTException(const char* msg) :std::runtime_error(msg)
- {}
- CBaseRTException() = default;
- ~CBaseRTException() = default;
- };
- }
- }
- #define SP_INTERNAL_LINEINFO ::SP::Detail::SourceLineInfo( __FILE__, static_cast<std::size_t>( __LINE__ ) )
- #endif /** _RVC_CATCH_H__*/
|