37#ifndef _EXCEPTION_HPP_
38#define _EXCEPTION_HPP_
74 Exception(
const std::string& rMessage,
const std::string& rFilename,
unsigned lineNumber);
125 static void Terminate(
const std::string& rMessage,
const std::string& rFilename,
unsigned lineNumber);
132 virtual const char*
what() const noexcept override;
144 const std::
string& rFilename,
unsigned lineNumber);
156#define EXCEPTION(message) \
158 std::stringstream msg_stream; \
159 msg_stream << message; \
160 throw Exception(msg_stream.str(), __FILE__, __LINE__); \
163#include <boost/preprocessor/stringize.hpp>
171#define EXCEPT_IF_NOT(test) \
172 if (!(test)) EXCEPTION("Assertion tripped: " BOOST_PP_STRINGIZE(test))
179#define EXCEPT_IF(test) \
180 if (test) EXCEPTION("Assertion tripped: " BOOST_PP_STRINGIZE(test))
189#define TERMINATE(message) \
191 std::stringstream msg_stream; \
192 msg_stream << message; \
193 Exception::Terminate(msg_stream.str(), __FILE__, __LINE__); \
227#define NEVER_REACHED TERMINATE("Should have been impossible to reach this line of code"); exit(EXIT_FAILURE)
235#define UNUSED_OPT(var) var=var
237#define UNUSED_OPT(var)
246#define ABORT_IF_THROWS(block) \
249 } catch (const Exception& e) { \
250 TERMINATE(e.GetMessage()); \
251 } catch (const std::exception &e) { \
252 TERMINATE(e.what()); \
254 TERMINATE("Unexpected exception thrown."); \
275#define EXPECT0(cmd, arg) { \
276 std::string _arg(arg); \
277 int retcode = cmd(_arg.c_str()); \
278 if (retcode != 0) { \
279 EXCEPTION("Error executing command: " #cmd "(" + _arg + ")"); \
291#define ABORT_IF_NON0_WITH_MSG(retcode, msg) \
292 if (retcode != 0) { \
308#define ABORT_IF_NON0(cmd, arg) { \
309 std::string _arg(arg); \
310 int ret = cmd(_arg.c_str()); \
311 ABORT_IF_NON0_WITH_MSG(ret, "Error executing command: " #cmd "(" + _arg + ")") \
322#define EXPECT_NON0(cmd, arg) { \
323 std::string _arg = (arg); \
324 int ret = cmd(_arg.c_str()); \
326 EXCEPTION("Command: " #cmd "(" + _arg + ") succeeded and it shouldn't have"); \
337#define IGNORE_RET(cmd, arg) { \
338 std::string _arg = (arg); \
339 int ret = cmd(_arg.c_str()); \
const double DOUBLE_UNSET
const unsigned UNSIGNED_UNSET
std::string GetMessage() const
void SetMessage(const std::string &rMessage, const std::string &rFilename, unsigned lineNumber)
std::string mShortMessage
std::string CheckShortMessageContains(const std::string &rExpected) const
virtual ~Exception()=default
static void Terminate(const std::string &rMessage, const std::string &rFilename, unsigned lineNumber)
virtual const char * what() const noexcept override
std::string GetShortMessage() const
std::string CheckShortMessage(const std::string &rExpected) const