18 #define THROW_TYPED_EXCEPTION(msg, exceptionClass) \ 19 throw exceptionClass( \ 20 throw_typed_exception(msg, __CURRENT_FUNCTION_NAME__, __LINE__)) 24 const T& msg,
const char* function_name,
unsigned int line)
26 std::string s =
"\n\n =============== MRPT EXCEPTION =============\n";
41 #define THROW_EXCEPTION(msg) THROW_TYPED_EXCEPTION(msg, std::logic_error); 43 #define THROW_EXCEPTION_FMT(_FORMAT_STRING, ...) \ 44 THROW_EXCEPTION(mrpt::format(_FORMAT_STRING, __VA_ARGS__)); 46 #define THROW_TYPED_EXCEPTION_FMT(exceptionClass, _FORMAT_STRING, ...) \ 47 THROW_TYPED_EXCEPTION( \ 48 mrpt::format(_FORMAT_STRING, __VA_ARGS__), exceptionClass) 53 #define THROW_STACKED_EXCEPTION(e) \ 54 throw std::logic_error(throw_stacked_exception( \ 55 e, __FILE__, __LINE__, __CURRENT_FUNCTION_NAME__)) 59 E&& e,
const char* file,
unsigned long line,
const char* funcName)
77 #define THROW_STACKED_EXCEPTION_CUSTOM_MSG2(e, stuff, param1) \ 78 throw std::logic_error(throw_stacked_exception_custom_msg2(e, stuff, param1)) 79 template <
typename E,
typename T>
81 E&& e,
const char* stuff, T&& param1)
90 #define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V) \ 91 THROW_EXCEPTION(mrpt::format( \ 92 "Cannot parse object: unknown serialization version number: '%i'", \ 93 static_cast<int>(__V))) 101 #define ASSERTMSG_(f, __ERROR_MSG) \ 104 if (!(f)) THROW_EXCEPTION(::std::string(__ERROR_MSG)); \ 114 ASSERTMSG_(f, std::string("Assert condition failed: ") + ::std::string(#f)) 118 #define MRPT_CHECK_NORMAL_NUMBER(v) \ 121 ASSERT_(std::isfinite(v)); \ 122 ASSERT_(!std::isnan(v)); \ 127 #define MRPT_COMPILE_TIME_ASSERT(expression) \ 128 static_assert(expression, #expression) 130 #define ASRT_FAIL(__CONDITIONSTR, __A, __B, __ASTR, __BSTR) \ 131 THROW_EXCEPTION(asrt_fail(__CONDITIONSTR, __A, __B, __ASTR, __BSTR)) 132 template <
typename A,
typename B>
140 s +=
") failed with\n";
153 #define ASSERT_EQUAL_(__A, __B) \ 156 if (__A != __B) ASRT_FAIL("ASSERT_EQUAL_", __A, __B, #__A, #__B) \ 159 #define ASSERT_NOT_EQUAL_(__A, __B) \ 162 if (__A == __B) ASRT_FAIL("ASSERT_NOT_EQUAL_", __A, __B, #__A, #__B) \ 165 #define ASSERT_BELOW_(__A, __B) \ 168 if (__A >= __B) ASRT_FAIL("ASSERT_BELOW_", __A, __B, #__A, #__B) \ 171 #define ASSERT_ABOVE_(__A, __B) \ 174 if (__A <= __B) ASRT_FAIL("ASSERT_ABOVE_", __A, __B, #__A, #__B) \ 177 #define ASSERT_BELOWEQ_(__A, __B) \ 180 if (__A > __B) ASRT_FAIL("ASSERT_BELOWEQ_", __A, __B, #__A, #__B) \ 183 #define ASSERT_ABOVEEQ_(__A, __B) \ 186 if (__A < __B) ASRT_FAIL("ASSERT_ABOVEEQ_", __A, __B, #__A, #__B) \ 196 #define ASSERTDEB_(f) ASSERT_(f) 197 #define ASSERTDEBMSG_(f, __ERROR_MSG) ASSERTMSG_(f, __ERROR_MSG) 198 #define ASSERTDEB_EQUAL_(__A, __B) ASSERT_EQUAL_(__A, __B) 199 #define ASSERTDEB_NOT_EQUAL_(__A, __B) ASSERT_NOT_EQUAL_(__A, __B) 200 #define ASSERTDEB_BELOW_(__A, __B) ASSERT_BELOW_(__A, __B) 201 #define ASSERTDEB_ABOVE_(__A, __B) ASSERT_ABOVE_(__A, __B) 202 #define ASSERTDEB_BELOWEQ_(__A, __B) ASSERT_BELOWEQ_(__A, __B) 203 #define ASSERTDEB_ABOVEEQ_(__A, __B) ASSERT_ABOVEEQ_(__A, __B) 205 #define ASSERTDEB_(f) \ 208 #define ASSERTDEBMSG_(f, __ERROR_MSG) \ 211 #define ASSERTDEB_EQUAL_(__A, __B) {} 212 #define ASSERTDEB_NOT_EQUAL_(__A, __B) {} 213 #define ASSERTDEB_BELOW_(__A, __B) {} 214 #define ASSERTDEB_ABOVE_(__A, __B) {} 215 #define ASSERTDEB_BELOWEQ_(__A, __B) {} 216 #define ASSERTDEB_ABOVEEQ_(__A, __B) {} 224 #define MRPT_TRY_START \ 231 #define MRPT_TRY_END \ 233 catch (std::bad_alloc&) { throw; } \ 234 catch (std::exception & __excep) { THROW_STACKED_EXCEPTION(__excep); } \ 235 catch (...) { THROW_EXCEPTION("Unexpected runtime error!"); } 241 #define MRPT_TRY_END_WITH_CLEAN_UP(stuff) \ 243 catch (std::bad_alloc&) { throw; } \ 244 catch (std::exception & __excep) \ 246 {stuff} THROW_STACKED_EXCEPTION(__excep); \ 248 catch (...) { {stuff} THROW_EXCEPTION("Unexpected runtime error!"); } 250 #if MRPT_ENABLE_EMBEDDED_GLOBAL_PROFILER 251 #define MRPT_PROFILE_FUNC_START \ 252 ::mrpt::utils::CProfilerProxy BOOST_JOIN( \ 253 __dum_var, __LINE__)(__CURRENT_FUNCTION_NAME__); 255 #define MRPT_PROFILE_FUNC_START 263 MRPT_PROFILE_FUNC_START \ 266 #define MRPT_END MRPT_TRY_END 268 #define MRPT_END_WITH_CLEAN_UP(stuff) MRPT_TRY_END_WITH_CLEAN_UP(stuff) std::string asrt_fail(std::string s, A &&a, B &&b, const char *astr, const char *bstr)
std::string throw_stacked_exception_custom_msg2(E &&e, const char *stuff, T &¶m1)
GLsizei const GLchar ** string
std::string throw_typed_exception(const T &msg, const char *function_name, unsigned int line)
std::string throw_stacked_exception(E &&e, const char *file, unsigned long line, const char *funcName)
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
std::string std::string to_string(T v)
Just like std::to_string(), but with an overloaded version for std::string arguments.
GLubyte GLubyte GLubyte a