Macros for exception handling

1. Exception classes

All exceptions that can be raised by MRPT API are derived from the C++ standard std::exception, so if you want to catch all of them, your code should have (at least at the top level, for example, in main() ) the following try/catch block:

In fact, all MRPT exceptions are of the types (derived from std::exception):

So if you want to handle in a different way one specific type of error, the following can be done:

2. Exception raising macros (assert-like MACROS)


Note that there’s no need to add a semicolon (;) at the end of the macros above.


3. Special MACROS for exception propagation

Most MRPT functions and methods use MRPT_START/MRPT_END macros, which enables (among other things) to automatically display the inverse call stack upon an exception. The exception e.what() string will typically contain a stack trace like: