MRPT  2.0.4
Namespaces | Macros | Functions
exceptions.h File Reference
#include <mrpt/core/common.h>
#include <mrpt/core/format.h>
#include <stdexcept>
#include <string>
#include <string_view>

Go to the source code of this file.

Namespaces

 mrpt
 This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
 
 mrpt::internal
 

Macros

#define THROW_TYPED_EXCEPTION(msg, exceptionClass)
 
#define THROW_EXCEPTION(msg)   THROW_TYPED_EXCEPTION(msg, std::logic_error)
 
#define THROW_EXCEPTION_FMT(_FORMAT_STRING, ...)   THROW_EXCEPTION(mrpt::format(_FORMAT_STRING, __VA_ARGS__))
 
#define THROW_TYPED_EXCEPTION_FMT(exceptionClass, _FORMAT_STRING, ...)
 
#define THROW_STACKED_EXCEPTION
 
#define THROW_STACKED_EXCEPTION_CUSTOM_MSG2(stuff, param1)
 
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
 For use in CSerializable implementations. More...
 
#define ASSERTMSG_(f, __ERROR_MSG)
 Defines an assertion mechanism. More...
 
#define ASSERT_(f)   ASSERTMSG_(f, std::string("Assert condition failed: ") + ::std::string(#f))
 Defines an assertion mechanism. More...
 
#define MRPT_CHECK_NORMAL_NUMBER(v)
 Throws an exception if the number is NaN, IND, or +/-INF, or return the same number otherwise. More...
 
#define ASRT_FAIL(__CONDITIONSTR, __A, __B, __ASTR, __BSTR)
 
#define ASSERT_EQUAL_(__A, __B)
 Assert comparing two values, reporting their actual values upon failure. More...
 
#define ASSERT_NOT_EQUAL_(__A, __B)
 
#define ASSERT_BELOW_(__A, __B)
 
#define ASSERT_ABOVE_(__A, __B)
 
#define ASSERT_BELOWEQ_(__A, __B)
 
#define ASSERT_ABOVEEQ_(__A, __B)
 
#define ASSERTDEB_(f)   while (0){}
 Defines an assertion mechanism - only when compiled in debug. More...
 
#define ASSERTDEBMSG_(f, __ERROR_MSG)   while (0){}
 
#define ASSERTDEB_EQUAL_(__A, __B)   while (0){}
 
#define ASSERTDEB_NOT_EQUAL_(__A, __B)   while (0){}
 
#define ASSERTDEB_BELOW_(__A, __B)   while (0){}
 
#define ASSERTDEB_ABOVE_(__A, __B)   while (0){}
 
#define ASSERTDEB_BELOWEQ_(__A, __B)   while (0){}
 
#define ASSERTDEB_ABOVEEQ_(__A, __B)   while (0){}
 
#define MRPT_TRY_START
 The start of a standard MRPT "try...catch()" block that allows tracing throw the call stack after an exception. More...
 
#define MRPT_TRY_END
 The end of a standard MRPT "try...catch()" block that allows tracing throw the call stack after an exception. More...
 
#define MRPT_TRY_END_WITH_CLEAN_UP(stuff)
 The end of a standard MRPT "try...catch()" block that allows tracing throw the call stack after an exception, including a "clean up" piece of code to be run before throwing the exceptions. More...
 
#define MRPT_PROFILE_FUNC_START
 
#define MRPT_START
 
#define MRPT_END   MRPT_TRY_END
 
#define MRPT_END_WITH_CLEAN_UP(stuff)   MRPT_TRY_END_WITH_CLEAN_UP(stuff)
 

Functions

std::string mrpt::internal::exception_line_msg (const std::string_view &msg, const char *filename, unsigned int line, const char *function_name)
 
template<typename A , typename B >
std::string mrpt::internal::asrt_fail (std::string s, A &&a, B &&b, const char *astr, const char *bstr)
 
std::string mrpt::exception_to_str (const std::exception &e)
 Builds a nice textual representation of a nested exception, which if generated using MRPT macros (THROW_EXCEPTION,...) in between MRPT_START/MRPT_END macros, will contain function names and line numbers across the call stack at the original throw point. More...
 

Macro Definition Documentation

◆ ASRT_FAIL

#define ASRT_FAIL (   __CONDITIONSTR,
  __A,
  __B,
  __ASTR,
  __BSTR 
)
Value:
mrpt::internal::asrt_fail(__CONDITIONSTR, __A, __B, __ASTR, __BSTR));

Definition at line 133 of file exceptions.h.

◆ ASSERT_

#define ASSERT_ (   f)    ASSERTMSG_(f, std::string("Assert condition failed: ") + ::std::string(#f))

Defines an assertion mechanism.

Note
Do NOT put code that must be always executed inside this statement, but just comparisons. This is because users might require ASSERT_'s to be ignored for optimized releases.
See also
MRPT_TRY_START, MRPT_TRY_END

Definition at line 121 of file exceptions.h.

◆ ASSERT_ABOVE_

#define ASSERT_ABOVE_ (   __A,
  __B 
)
Value:
do \
{ \
if (__A <= __B) ASRT_FAIL("ASSERT_ABOVE_", __A, __B, #__A, #__B) \
} while (0)

Definition at line 156 of file exceptions.h.

◆ ASSERT_ABOVEEQ_

#define ASSERT_ABOVEEQ_ (   __A,
  __B 
)
Value:
do \
{ \
if (__A < __B) ASRT_FAIL("ASSERT_ABOVEEQ_", __A, __B, #__A, #__B) \
} while (0)

Definition at line 168 of file exceptions.h.

◆ ASSERT_BELOW_

#define ASSERT_BELOW_ (   __A,
  __B 
)
Value:
do \
{ \
if (__A >= __B) ASRT_FAIL("ASSERT_BELOW_", __A, __B, #__A, #__B) \
} while (0)

Definition at line 150 of file exceptions.h.

◆ ASSERT_BELOWEQ_

#define ASSERT_BELOWEQ_ (   __A,
  __B 
)
Value:
do \
{ \
if (__A > __B) ASRT_FAIL("ASSERT_BELOWEQ_", __A, __B, #__A, #__B) \
} while (0)

Definition at line 162 of file exceptions.h.

◆ ASSERT_EQUAL_

#define ASSERT_EQUAL_ (   __A,
  __B 
)
Value:
do \
{ \
if (__A != __B) ASRT_FAIL("ASSERT_EQUAL_", __A, __B, #__A, #__B) \
} while (0)

Assert comparing two values, reporting their actual values upon failure.

Definition at line 138 of file exceptions.h.

◆ ASSERT_NOT_EQUAL_

#define ASSERT_NOT_EQUAL_ (   __A,
  __B 
)
Value:
do \
{ \
if (__A == __B) ASRT_FAIL("ASSERT_NOT_EQUAL_", __A, __B, #__A, #__B) \
} while (0)

Definition at line 144 of file exceptions.h.

◆ ASSERTDEB_

#define ASSERTDEB_ (   f)    while (0){}

Defines an assertion mechanism - only when compiled in debug.

Note
Do NOT put code that must be always executed inside this statement, but just comparisons. This is because users might require ASSERT_'s to be ignored for optimized releases.
See also
MRPT_TRY_START, MRPT_TRY_END

Definition at line 191 of file exceptions.h.

◆ ASSERTDEB_ABOVE_

#define ASSERTDEB_ABOVE_ (   __A,
  __B 
)    while (0){}

Definition at line 196 of file exceptions.h.

◆ ASSERTDEB_ABOVEEQ_

#define ASSERTDEB_ABOVEEQ_ (   __A,
  __B 
)    while (0){}

Definition at line 198 of file exceptions.h.

◆ ASSERTDEB_BELOW_

#define ASSERTDEB_BELOW_ (   __A,
  __B 
)    while (0){}

Definition at line 195 of file exceptions.h.

◆ ASSERTDEB_BELOWEQ_

#define ASSERTDEB_BELOWEQ_ (   __A,
  __B 
)    while (0){}

Definition at line 197 of file exceptions.h.

◆ ASSERTDEB_EQUAL_

#define ASSERTDEB_EQUAL_ (   __A,
  __B 
)    while (0){}

Definition at line 193 of file exceptions.h.

◆ ASSERTDEB_NOT_EQUAL_

#define ASSERTDEB_NOT_EQUAL_ (   __A,
  __B 
)    while (0){}

Definition at line 194 of file exceptions.h.

◆ ASSERTDEBMSG_

#define ASSERTDEBMSG_ (   f,
  __ERROR_MSG 
)    while (0){}

Definition at line 192 of file exceptions.h.

◆ ASSERTMSG_

#define ASSERTMSG_ (   f,
  __ERROR_MSG 
)
Value:
do \
{ \
if (!(f)) THROW_EXCEPTION(::std::string(__ERROR_MSG)); \
} while (0)

Defines an assertion mechanism.

Note
Do NOT put code that must be always executed inside this statement, but just comparisons. This is because users might require ASSERT_'s to be ignored for optimized releases.
See also
MRPT_TRY_START, MRPT_TRY_END

Definition at line 109 of file exceptions.h.

◆ MRPT_CHECK_NORMAL_NUMBER

#define MRPT_CHECK_NORMAL_NUMBER (   v)
Value:
do \
{ \
ASSERT_(std::isfinite(v)); \
ASSERT_(!std::isnan(v)); \
} while (0)

Throws an exception if the number is NaN, IND, or +/-INF, or return the same number otherwise.

Definition at line 126 of file exceptions.h.

◆ MRPT_END

#define MRPT_END   MRPT_TRY_END
Examples
core_exceptions_example/test.cpp.

Definition at line 246 of file exceptions.h.

◆ MRPT_END_WITH_CLEAN_UP

#define MRPT_END_WITH_CLEAN_UP (   stuff)    MRPT_TRY_END_WITH_CLEAN_UP(stuff)

Definition at line 248 of file exceptions.h.

◆ MRPT_PROFILE_FUNC_START

#define MRPT_PROFILE_FUNC_START

Definition at line 235 of file exceptions.h.

◆ MRPT_START

#define MRPT_START
Value:
MRPT_PROFILE_FUNC_START \
MRPT_TRY_START
Examples
core_exceptions_example/test.cpp.

Definition at line 242 of file exceptions.h.

◆ MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION

#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION (   __V)
Value:
"Cannot parse object: unknown serialization version number: '%i'", \
static_cast<int>(__V)))

For use in CSerializable implementations.

Definition at line 98 of file exceptions.h.

◆ MRPT_TRY_END

#define MRPT_TRY_END
Value:
} \
catch (std::bad_alloc&) { throw; } \
catch (...) { THROW_STACKED_EXCEPTION; }

The end of a standard MRPT "try...catch()" block that allows tracing throw the call stack after an exception.

See also
MRPT_TRY_START,MRPT_TRY_END_WITH_CLEAN_UP

Definition at line 214 of file exceptions.h.

◆ MRPT_TRY_END_WITH_CLEAN_UP

#define MRPT_TRY_END_WITH_CLEAN_UP (   stuff)
Value:
} \
catch (std::bad_alloc&) { throw; } \
catch (...) { {stuff} THROW_STACKED_EXCEPTION; }

The end of a standard MRPT "try...catch()" block that allows tracing throw the call stack after an exception, including a "clean up" piece of code to be run before throwing the exceptions.

See also
MRPT_TRY_END,MRPT_TRY_START

Definition at line 225 of file exceptions.h.

◆ MRPT_TRY_START

#define MRPT_TRY_START
Value:
try \
{

The start of a standard MRPT "try...catch()" block that allows tracing throw the call stack after an exception.

See also
MRPT_TRY_END,MRPT_TRY_END_WITH_CLEAN_UP

Definition at line 207 of file exceptions.h.

◆ THROW_EXCEPTION

#define THROW_EXCEPTION (   msg)    THROW_TYPED_EXCEPTION(msg, std::logic_error)
Parameters
msgThis can be a char*, a std::string, or a literal string. Defines a unified way of reporting exceptions
See also
MRPT_TRY_START, MRPT_TRY_END, THROW_EXCEPTION_FMT
Examples
core_exceptions_example/test.cpp.

Definition at line 68 of file exceptions.h.

◆ THROW_EXCEPTION_FMT

#define THROW_EXCEPTION_FMT (   _FORMAT_STRING,
  ... 
)    THROW_EXCEPTION(mrpt::format(_FORMAT_STRING, __VA_ARGS__))

Definition at line 70 of file exceptions.h.

◆ THROW_STACKED_EXCEPTION

#define THROW_STACKED_EXCEPTION
Value:
std::throw_with_nested( \
"Called from here.", __FILE__, __LINE__, \
See also
MRPT_TRY_START, MRPT_TRY_END

Definition at line 80 of file exceptions.h.

◆ THROW_STACKED_EXCEPTION_CUSTOM_MSG2

#define THROW_STACKED_EXCEPTION_CUSTOM_MSG2 (   stuff,
  param1 
)
Value:
std::throw_with_nested( \
mrpt::format(stuff, param1), __FILE__, __LINE__, \

Definition at line 91 of file exceptions.h.

◆ THROW_TYPED_EXCEPTION

#define THROW_TYPED_EXCEPTION (   msg,
  exceptionClass 
)
Value:
throw exceptionClass(mrpt::internal::exception_line_msg( \
msg, __FILE__, __LINE__, __CURRENT_FUNCTION_NAME__))

Definition at line 59 of file exceptions.h.

◆ THROW_TYPED_EXCEPTION_FMT

#define THROW_TYPED_EXCEPTION_FMT (   exceptionClass,
  _FORMAT_STRING,
  ... 
)
Value:
mrpt::format(_FORMAT_STRING, __VA_ARGS__), exceptionClass)

Definition at line 73 of file exceptions.h.

mrpt::internal::exception_line_msg
std::string exception_line_msg(const std::string_view &msg, const char *filename, unsigned int line, const char *function_name)
Definition: exceptions.cpp:16
__CURRENT_FUNCTION_NAME__
#define __CURRENT_FUNCTION_NAME__
A macro for obtaining the name of the current function:
Definition: common.h:134
THROW_EXCEPTION
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:67
mrpt::internal::asrt_fail
std::string asrt_fail(std::string s, A &&a, B &&b, const char *astr, const char *bstr)
Definition: exceptions.h:25
THROW_TYPED_EXCEPTION
#define THROW_TYPED_EXCEPTION(msg, exceptionClass)
Definition: exceptions.h:58
ASRT_FAIL
#define ASRT_FAIL(__CONDITIONSTR, __A, __B, __ASTR, __BSTR)
Definition: exceptions.h:132
mrpt::format
std::string std::string format(std::string_view fmt, ARGS &&... args)
Definition: format.h:26
THROW_STACKED_EXCEPTION
#define THROW_STACKED_EXCEPTION
Definition: exceptions.h:79



Page generated by Doxygen 1.8.18 for MRPT 2.0.4 at Thu Sep 24 07:14:18 UTC 2020