47 #ifndef _MIRA_EXCEPTION_H_ 48 #define _MIRA_EXCEPTION_H_ 82 #define MIRA_THROW(ex, msg) \ 84 std::ostringstream ex_str; \ 86 constexpr auto fileInMIRAPath = mira::chopMIRAPath(__FILE__); \ 87 throw ex(ex_str.str(), fileInMIRAPath, __LINE__).addStackInfo<ex>(); \ 96 #define MIRA_THROW_NOSTACK(ex, msg) \ 98 std::ostringstream ex_str; \ 100 constexpr auto fileInMIRAPath = mira::chopMIRAPath(__FILE__); \ 101 throw ex(ex_str.str(), fileInMIRAPath, __LINE__); \ 111 #define MIRA_THROW_EXTSTACK(ex, msg, stack, thread) \ 113 std::ostringstream ex_str; \ 115 constexpr auto fileInMIRAPath = mira::chopMIRAPath(__FILE__); \ 116 throw ex(ex_str.str(), fileInMIRAPath, __LINE__) \ 117 .addExternalStackInfo<ex>(stack, thread); \ 148 #define MIRA_RETHROW(ex, msg) \ 150 std::ostringstream ex_str; \ 152 constexpr auto fileInMIRAPath = mira::chopMIRAPath(__FILE__); \ 153 ex.addInfo(ex_str.str(),fileInMIRAPath, __LINE__); \ 170 #define MIRA_DEFINE_EXCEPTION(Ex, Base) \ 171 class Ex : public Base \ 174 Ex(std::string msg, const char* file=NULL, int line=0) MIRA_NOEXCEPT_OR_NOTHROW : \ 175 Base(std::move(msg), file, line) {} \ 177 virtual ~Ex() MIRA_NOEXCEPT_OR_NOTHROW {} \ 215 addInfo(std::move(message),
file, line);
230 void addInfo(std::string message,
const char*
file=NULL,
int line=0)
232 mInfos.emplace_back(std::move(message),
file ? std::string(
file) :
"", line);
271 template <
typename DerivedException>
275 mStack = createCallStack();
276 mThreadID = getCurrentThreadID();
277 return (DerivedException&)*
this;
285 template <
typename DerivedException>
288 mStack = std::move(stack);
290 return (DerivedException&)*
this;
308 Info(std::string iMessage, std::string iFile,
int iLine) :
309 message(
std::move(iMessage)),
file(
std::move(iFile)), line(iLine) {}
311 std::string what(std::size_t messageWidth)
const;
316 const Info&
getInfo()
const { assert(!mInfos.empty());
return mInfos.front(); }
CallStack mStack
Definition: Exception.h:320
Encapsulates call stack functionality.
const Info & getInfo() const
Returns the first info packet that describes the location where the exception has occured...
Definition: Exception.h:316
Exception(std::string message, const char *file=NULL, int line=0) MIRA_NOEXCEPT_OR_NOTHROW
The constructor.
Definition: Exception.h:213
PropertyHint file(const std::string &filters=std::string(), bool save=false)
Tells the property editor that the path is for a file, and that it should show a "File Open"/"File Sa...
Definition: Path.h:247
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
Compile-time path handling.
std::string file
The file the exception occurred.
Definition: Exception.h:304
void addInfo(std::string message, const char *file=NULL, int line=0)
Adds additional information to the exception.
Definition: Exception.h:230
DerivedException & addStackInfo()
FOR INTERNAL USE ONLY.
Definition: Exception.h:272
uint32 ThreadID
Platform independent thread ID.
Definition: ThreadID.h:68
std::string mMessage
as cache for what()
Definition: Exception.h:322
ThreadID mThreadID
Definition: Exception.h:321
OS independent thread id.
int line
The line the exception occurred.
Definition: Exception.h:305
#define MIRA_NOEXCEPT_OR_NOTHROW
Definition: NoExcept.h:99
std::list< Info > mInfos
Definition: Exception.h:319
Base class for exceptions.
Definition: Exception.h:199
The info packet that is added in MIRA_THROW and MIRA_RETHROW.
Definition: Exception.h:302
Encapsulates unix call stack functionality.
Definition: CallStack.h:86
DerivedException & addExternalStackInfo(CallStack stack, ThreadID thread)
Stores the provided callstack and thread id within the exception.
Definition: Exception.h:286
Exception() MIRA_NOEXCEPT_OR_NOTHROW
Definition: Exception.h:202
Info(std::string iMessage, std::string iFile, int iLine)
Definition: Exception.h:308
virtual ~Exception() MIRA_NOEXCEPT_OR_NOTHROW
Destructor.
Definition: Exception.h:219
Compatible no-exception throwing specification.
std::string message
The exception message.
Definition: Exception.h:303
ThreadID getThreadID() const
Returns the id of the thread where the exception was thrown.
Definition: Exception.h:261