16 #include <string_view> 21 const std::string_view& msg,
const char* filename,
unsigned int line,
22 const char* function_name);
24 template <
typename A,
typename B>
26 std::string s,
A&& a, B&& b,
const char* astr,
const char* bstr)
32 s +=
") failed with\n";
58 #define THROW_TYPED_EXCEPTION(msg, exceptionClass) \ 59 throw exceptionClass(mrpt::internal::exception_line_msg( \ 60 msg, __FILE__, __LINE__, __CURRENT_FUNCTION_NAME__)) 67 #define THROW_EXCEPTION(msg) THROW_TYPED_EXCEPTION(msg, std::logic_error) 69 #define THROW_EXCEPTION_FMT(_FORMAT_STRING, ...) \ 70 THROW_EXCEPTION(mrpt::format(_FORMAT_STRING, __VA_ARGS__)) 72 #define THROW_TYPED_EXCEPTION_FMT(exceptionClass, _FORMAT_STRING, ...) \ 73 THROW_TYPED_EXCEPTION( \ 74 mrpt::format(_FORMAT_STRING, __VA_ARGS__), exceptionClass) 79 #define THROW_STACKED_EXCEPTION \ 80 std::throw_with_nested( \ 81 std::logic_error(mrpt::internal::exception_line_msg( \ 82 "Called from here.", __FILE__, __LINE__, \ 83 __CURRENT_FUNCTION_NAME__))) 90 #define THROW_STACKED_EXCEPTION_CUSTOM_MSG2(stuff, param1) \ 91 std::throw_with_nested( \ 92 std::logic_error(mrpt::internal::exception_line_msg( \ 93 mrpt::format(stuff, param1), __FILE__, __LINE__, \ 94 __CURRENT_FUNCTION_NAME__))) 97 #define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V) \ 98 THROW_EXCEPTION(mrpt::format( \ 99 "Cannot parse object: unknown serialization version number: '%i'", \ 100 static_cast<int>(__V))) 108 #define ASSERTMSG_(f, __ERROR_MSG) \ 111 if (!(f)) THROW_EXCEPTION(::std::string(__ERROR_MSG)); \ 121 ASSERTMSG_(f, std::string("Assert condition failed: ") + ::std::string(#f)) 125 #define MRPT_CHECK_NORMAL_NUMBER(v) \ 128 ASSERT_(std::isfinite(v)); \ 129 ASSERT_(!std::isnan(v)); \ 132 #define ASRT_FAIL(__CONDITIONSTR, __A, __B, __ASTR, __BSTR) \ 134 mrpt::internal::asrt_fail(__CONDITIONSTR, __A, __B, __ASTR, __BSTR)); 137 #define ASSERT_EQUAL_(__A, __B) \ 140 if (__A != __B) ASRT_FAIL("ASSERT_EQUAL_", __A, __B, #__A, #__B) \ 143 #define ASSERT_NOT_EQUAL_(__A, __B) \ 146 if (__A == __B) ASRT_FAIL("ASSERT_NOT_EQUAL_", __A, __B, #__A, #__B) \ 149 #define ASSERT_BELOW_(__A, __B) \ 152 if (__A >= __B) ASRT_FAIL("ASSERT_BELOW_", __A, __B, #__A, #__B) \ 155 #define ASSERT_ABOVE_(__A, __B) \ 158 if (__A <= __B) ASRT_FAIL("ASSERT_ABOVE_", __A, __B, #__A, #__B) \ 161 #define ASSERT_BELOWEQ_(__A, __B) \ 164 if (__A > __B) ASRT_FAIL("ASSERT_BELOWEQ_", __A, __B, #__A, #__B) \ 167 #define ASSERT_ABOVEEQ_(__A, __B) \ 170 if (__A < __B) ASRT_FAIL("ASSERT_ABOVEEQ_", __A, __B, #__A, #__B) \ 180 #define ASSERTDEB_(f) ASSERT_(f) 181 #define ASSERTDEBMSG_(f, __ERROR_MSG) ASSERTMSG_(f, __ERROR_MSG) 182 #define ASSERTDEB_EQUAL_(__A, __B) ASSERT_EQUAL_(__A, __B) 183 #define ASSERTDEB_NOT_EQUAL_(__A, __B) ASSERT_NOT_EQUAL_(__A, __B) 184 #define ASSERTDEB_BELOW_(__A, __B) ASSERT_BELOW_(__A, __B) 185 #define ASSERTDEB_ABOVE_(__A, __B) ASSERT_ABOVE_(__A, __B) 186 #define ASSERTDEB_BELOWEQ_(__A, __B) ASSERT_BELOWEQ_(__A, __B) 187 #define ASSERTDEB_ABOVEEQ_(__A, __B) ASSERT_ABOVEEQ_(__A, __B) 190 #define ASSERTDEB_(f) while (0){} 191 #define ASSERTDEBMSG_(f, __ERROR_MSG) while (0){} 192 #define ASSERTDEB_EQUAL_(__A, __B) while (0){} 193 #define ASSERTDEB_NOT_EQUAL_(__A, __B) while (0){} 194 #define ASSERTDEB_BELOW_(__A, __B) while (0){} 195 #define ASSERTDEB_ABOVE_(__A, __B) while (0){} 196 #define ASSERTDEB_BELOWEQ_(__A, __B) while (0){} 197 #define ASSERTDEB_ABOVEEQ_(__A, __B) while (0){} 206 #define MRPT_TRY_START \ 213 #define MRPT_TRY_END \ 215 catch (std::bad_alloc&) { throw; } \ 216 catch (...) { THROW_STACKED_EXCEPTION; } 224 #define MRPT_TRY_END_WITH_CLEAN_UP(stuff) \ 226 catch (std::bad_alloc&) { throw; } \ 227 catch (...) { {stuff} THROW_STACKED_EXCEPTION; } 229 #if MRPT_ENABLE_EMBEDDED_GLOBAL_PROFILER 230 #define MRPT_PROFILE_FUNC_START \ 231 ::mrpt::system::CProfilerProxy BOOST_JOIN( \ 232 __dum_var, __LINE__)(__CURRENT_FUNCTION_NAME__); 234 #define MRPT_PROFILE_FUNC_START 242 MRPT_PROFILE_FUNC_START \ 245 #define MRPT_END MRPT_TRY_END 247 #define MRPT_END_WITH_CLEAN_UP(stuff) MRPT_TRY_END_WITH_CLEAN_UP(stuff) std::string to_string(T v)
Just like std::to_string(), but with an overloaded version for std::string arguments.
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
std::string exception_to_str(const std::exception &e)
Builds a nice textual representation of a nested exception, which if generated using MRPT macros (THR...
std::string exception_line_msg(const std::string_view &msg, const char *filename, unsigned int line, const char *function_name)
std::string asrt_fail(std::string s, A &&a, B &&b, const char *astr, const char *bstr)