52#ifndef LASS_GUARDIAN_OF_INCLUSION_UTIL_EXCEPTION_H
53#define LASS_GUARDIAN_OF_INCLUSION_UTIL_EXCEPTION_H
65class RemoteExceptionBase;
67typedef std::unique_ptr<RemoteExceptionBase> TRemoteExceptionBasePtr;
72 virtual ~RemoteExceptionBase();
73 void throwSelf()
const;
74 TRemoteExceptionBasePtr clone()
const;
77 virtual void doThrowSelf()
const = 0;
78 virtual RemoteExceptionBase* doClone()
const = 0;
82class Exception:
public std::exception,
public RemoteExceptionBase
85 Exception(std::string message, std::string location):
86 message_(std::move(message)),
87 location_(std::move(location))
90 explicit Exception(std::string message):
91 Exception(std::move(message), std::string())
95 Exception(std::string(), std::string())
98 ~Exception()
noexcept {}
99 const char* what()
const noexcept override {
return message_.c_str(); }
100 const std::string& message()
const {
return message_; }
101 const std::string& location()
const {
return location_; }
103 std::string message_;
104 std::string location_;
105 void doThrowSelf()
const override {
throw *
this; }
106 RemoteExceptionBase* doClone()
const override {
return new Exception(*
this); }
111template <
typename ExceptionType,
typename ParentType = Exception>
112class ExceptionMixin:
public ParentType
115 ExceptionMixin(std::string message, std::string location):
116 ParentType(std::move(message), std::move(location))
119 explicit ExceptionMixin(std::string message):
120 ParentType(std::move(message))
123 ~ExceptionMixin() noexcept {}
125 virtual void doThrowSelf()
const override
127 throw *
static_cast<const ExceptionType*
>(
this);
129 virtual RemoteExceptionBase* doClone()
const override
131 return new ExceptionType(*
static_cast<const ExceptionType*
>(
this));
137template <
typename LocalException>
138class RemoteExceptionWrapper:
139 public virtual LocalException,
140 public virtual RemoteExceptionBase
143 RemoteExceptionWrapper(
const LocalException& e): LocalException(e) {}
144 ~RemoteExceptionWrapper() noexcept {}
146 void doThrowSelf()
const override
150 RemoteExceptionBase* doClone()
const override
152 typedef RemoteExceptionWrapper<LocalException> TSelf;
153 return new TSelf(*
static_cast<const LocalException*
>(
this));
159class KeyError:
public ExceptionMixin<KeyError>
162 KeyError(std::string msg, std::string loc): ExceptionMixin<KeyError>(std::move(msg), std::move(loc)) {}
163 ~KeyError() noexcept {}
167class ValueError:
public ExceptionMixin<ValueError>
170 ValueError(std::string msg, std::string loc) : ExceptionMixin<ValueError>(std::move(msg), std::move(loc)) {}
171 ~ValueError() noexcept {}
174class SingularityError:
public ExceptionMixin<SingularityError>
177 SingularityError(std::string msg, std::string loc) : ExceptionMixin<SingularityError>(std::move(msg), std::move(loc)) {}
178 ~SingularityError() noexcept {}
202#define LASS_THROW_EX(t_exception, s_message)\
205 ::std::ostringstream lassUtilExceptionImplBuffer;\
206 lassUtilExceptionImplBuffer << s_message;\
207 throw t_exception(lassUtilExceptionImplBuffer.str(), LASS_PRETTY_FUNCTION);\
218#define LASS_THROW(s_message) LASS_THROW_EX(::lass::util::Exception, s_message)
226#define LASS_CATCH_TO_WARNING\
227 catch (const ::std::exception& error)\
229 std::cerr << "[LASS RUN MSG] UNDEFINED BEHAVIOUR WARNING: Exception caught in "\
230 << LASS_PRETTY_FUNCTION << ":\n" << error.what() << std::endl;\
234 std::cerr << "[LASS RUN MSG] UNDEFINED BEHAVIOUR WARNING: Unknown exception caught in "\
235 << LASS_PRETTY_FUNCTION << std::endl;\
#define LASS_DLL
DLL interface: import or export symbols?
general utility, debug facilities, ...
Library for Assembled Shared Sources.