Main MRPT website > C++ reference for MRPT 1.9.9
Macros | Functions
exceptions.h File Reference
#include <string>
#include <stdexcept>
#include <mrpt/core/common.h>
#include <mrpt/core/format.h>
Include dependency graph for exceptions.h:

Go to the source code of this file.

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(e)
 
#define THROW_STACKED_EXCEPTION_CUSTOM_MSG2(e, stuff, param1)   throw std::logic_error(throw_stacked_exception_custom_msg2(e, 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 MRPT_COMPILE_TIME_ASSERT(expression)   static_assert(expression, #expression)
 
#define ASRT_FAIL(__CONDITIONSTR, __A, __B, __ASTR, __BSTR)   THROW_EXCEPTION(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)
 Defines an assertion mechanism - only when compiled in debug. More...
 
#define ASSERTDEBMSG_(f, __ERROR_MSG)
 
#define ASSERTDEB_EQUAL_(__A, __B)   {}
 
#define ASSERTDEB_NOT_EQUAL_(__A, __B)   {}
 
#define ASSERTDEB_BELOW_(__A, __B)   {}
 
#define ASSERTDEB_ABOVE_(__A, __B)   {}
 
#define ASSERTDEB_BELOWEQ_(__A, __B)   {}
 
#define ASSERTDEB_ABOVEEQ_(__A, __B)   {}
 
#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

template<typename T >
std::string throw_typed_exception (const T &msg, const char *function_name, unsigned int line)
 
template<typename E >
std::string throw_stacked_exception (E &&e, const char *file, unsigned long line, const char *funcName)
 
template<typename E , typename T >
std::string throw_stacked_exception_custom_msg2 (E &&e, const char *stuff, T &&param1)
 
template<typename A , typename B >
std::string asrt_fail (std::string s, A &&a, B &&b, const char *astr, const char *bstr)
 

Macro Definition Documentation

◆ ASRT_FAIL

#define ASRT_FAIL (   __CONDITIONSTR,
  __A,
  __B,
  __ASTR,
  __BSTR 
)    THROW_EXCEPTION(asrt_fail(__CONDITIONSTR, __A, __B, __ASTR, __BSTR))

Definition at line 130 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 113 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 171 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 183 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 165 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 177 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 153 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 159 of file exceptions.h.

◆ ASSERTDEB_

#define ASSERTDEB_ (   f)
Value:
{ \
}

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 205 of file exceptions.h.

◆ ASSERTDEB_ABOVE_

#define ASSERTDEB_ABOVE_ (   __A,
  __B 
)    {}

Definition at line 214 of file exceptions.h.

◆ ASSERTDEB_ABOVEEQ_

#define ASSERTDEB_ABOVEEQ_ (   __A,
  __B 
)    {}

Definition at line 216 of file exceptions.h.

◆ ASSERTDEB_BELOW_

#define ASSERTDEB_BELOW_ (   __A,
  __B 
)    {}

Definition at line 213 of file exceptions.h.

◆ ASSERTDEB_BELOWEQ_

#define ASSERTDEB_BELOWEQ_ (   __A,
  __B 
)    {}

Definition at line 215 of file exceptions.h.

◆ ASSERTDEB_EQUAL_

#define ASSERTDEB_EQUAL_ (   __A,
  __B 
)    {}

Definition at line 211 of file exceptions.h.

◆ ASSERTDEB_NOT_EQUAL_

#define ASSERTDEB_NOT_EQUAL_ (   __A,
  __B 
)    {}

Definition at line 212 of file exceptions.h.

◆ ASSERTDEBMSG_

#define ASSERTDEBMSG_ (   f,
  __ERROR_MSG 
)
Value:
{ \
}

Definition at line 208 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 101 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 118 of file exceptions.h.

◆ MRPT_COMPILE_TIME_ASSERT

#define MRPT_COMPILE_TIME_ASSERT (   expression)    static_assert(expression, #expression)

Definition at line 127 of file exceptions.h.

◆ MRPT_END

#define MRPT_END   MRPT_TRY_END

Definition at line 266 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 268 of file exceptions.h.

◆ MRPT_PROFILE_FUNC_START

#define MRPT_PROFILE_FUNC_START

Definition at line 255 of file exceptions.h.

◆ MRPT_START

#define MRPT_START
Value:
MRPT_PROFILE_FUNC_START \
MRPT_TRY_START

Definition at line 262 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 90 of file exceptions.h.

◆ MRPT_TRY_END

#define MRPT_TRY_END
Value:
} \
catch (std::bad_alloc&) { throw; } \
catch (std::exception & __excep) { THROW_STACKED_EXCEPTION(__excep); } \
catch (...) { THROW_EXCEPTION("Unexpected runtime error!"); }

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 231 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 (std::exception & __excep) \
{ \
{stuff} THROW_STACKED_EXCEPTION(__excep); \
} \
catch (...) { {stuff} THROW_EXCEPTION("Unexpected runtime error!"); }

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 241 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 224 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

Definition at line 41 of file exceptions.h.

◆ THROW_EXCEPTION_FMT

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

Definition at line 43 of file exceptions.h.

◆ THROW_STACKED_EXCEPTION

#define THROW_STACKED_EXCEPTION (   e)
Value:
throw std::logic_error(throw_stacked_exception( \
e, __FILE__, __LINE__, __CURRENT_FUNCTION_NAME__))
See also
MRPT_TRY_START, MRPT_TRY_END

Definition at line 53 of file exceptions.h.

◆ THROW_STACKED_EXCEPTION_CUSTOM_MSG2

#define THROW_STACKED_EXCEPTION_CUSTOM_MSG2 (   e,
  stuff,
  param1 
)    throw std::logic_error(throw_stacked_exception_custom_msg2(e, stuff, param1))

Definition at line 77 of file exceptions.h.

◆ THROW_TYPED_EXCEPTION

#define THROW_TYPED_EXCEPTION (   msg,
  exceptionClass 
)
Value:
throw exceptionClass( \

Definition at line 18 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 46 of file exceptions.h.

Function Documentation

◆ asrt_fail()

template<typename A , typename B >
std::string asrt_fail ( std::string  s,
A &&  a,
B &&  b,
const char *  astr,
const char *  bstr 
)
inline

Definition at line 133 of file exceptions.h.

References mrpt::to_string().

◆ throw_stacked_exception()

template<typename E >
std::string throw_stacked_exception ( E &&  e,
const char *  file,
unsigned long  line,
const char *  funcName 
)
inline

Definition at line 58 of file exceptions.h.

References mrpt::to_string().

◆ throw_stacked_exception_custom_msg2()

template<typename E , typename T >
std::string throw_stacked_exception_custom_msg2 ( E &&  e,
const char *  stuff,
T &&  param1 
)
inline

Definition at line 80 of file exceptions.h.

References mrpt::format().

◆ throw_typed_exception()

template<typename T >
std::string throw_typed_exception ( const T &  msg,
const char *  function_name,
unsigned int  line 
)
inline

Definition at line 23 of file exceptions.h.

References mrpt::to_string().

THROW_STACKED_EXCEPTION
#define THROW_STACKED_EXCEPTION(e)
Definition: exceptions.h:53
__CURRENT_FUNCTION_NAME__
#define __CURRENT_FUNCTION_NAME__
A macro for obtaining the name of the current function:
Definition: common.h:150
throw_stacked_exception
std::string throw_stacked_exception(E &&e, const char *file, unsigned long line, const char *funcName)
Definition: exceptions.h:58
THROW_EXCEPTION
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:41
v
const GLdouble * v
Definition: glext.h:3678
mrpt::format
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
Definition: format.cpp:16
THROW_TYPED_EXCEPTION
#define THROW_TYPED_EXCEPTION(msg, exceptionClass)
Definition: exceptions.h:18
string
GLsizei const GLchar ** string
Definition: glext.h:4101
ASRT_FAIL
#define ASRT_FAIL(__CONDITIONSTR, __A, __B, __ASTR, __BSTR)
Definition: exceptions.h:130
throw_typed_exception
std::string throw_typed_exception(const T &msg, const char *function_name, unsigned int line)
Definition: exceptions.h:23



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST