Skip to content

iox::ErrorHandler🔗

This handler is needed for unit testing, special debugging cases and other corner cases where we'd like to explicitly suppress the error handling.

#include <error_handling.hpp>

Public Functions🔗

Name
cxx::GenericRAII SetTemporaryErrorHandler(const HandlerFunction & newHandler)
const char * ToString(const Error error)

Protected Functions🔗

Name
void ReactOnErrorLevel(const ErrorLevel level, const char * errorText)

Friends🔗

Name
void errorHandler(const Error error, const std::function< void()> errorCallBack, const ErrorLevel level)
Howto use the error handler correctly 1.) If the error you would like to handle is not listed in ICEORYX_ERRORS(error)... macro just add them like: error(MODULE_NAME__MY_FUNKY_ERROR) Attention: Create an error after the following convention: MODULE_NAME__A_CLEAR_BUT_SHORT_ERROR_DESCRIPTION And a long name is alright!

Public Functions Documentation🔗

function SetTemporaryErrorHandler🔗

static cxx::GenericRAII SetTemporaryErrorHandler(
    const HandlerFunction & newHandler
)

function ToString🔗

static const char * ToString(
    const Error error
)

Protected Functions Documentation🔗

function ReactOnErrorLevel🔗

static void ReactOnErrorLevel(
    const ErrorLevel level,
    const char * errorText
)

Friends🔗

friend errorHandler🔗

friend void errorHandler(
    const Error error,
    const std::function< void()> errorCallBack,
    const ErrorLevel level
);

Howto use the error handler correctly 1.) If the error you would like to handle is not listed in ICEORYX_ERRORS(error)... macro just add them like: error(MODULE_NAME__MY_FUNKY_ERROR) Attention: Create an error after the following convention: MODULE_NAME__A_CLEAR_BUT_SHORT_ERROR_DESCRIPTION And a long name is alright!

2.) Call errorHandler(Error::kMODULE_NAME__MY_FUNKY_ERROR); Please pay attention to the "k" prefix The defaults for errorCallback and ErrorLevel can also be overwritten: errorHandler( Error::kMODULE_NAME__MY_FUNKY_ERROR, []{ std::cout << "MyCustomCallback" << std::endl; }, ErrorLevel::MODERATE );

class PrettyClass {
    float division(float a, float b) {
        if ( b == 0.0f ) {
            errorHandler(Error::kPRETTY_CLASS__DIVISION_BY_ZERO);
        }
    }
};
bool called = false;
auto temporaryErrorHandler = ErrorHandler::SetTemporaryErrorHandler(
    [&](const Error e, std::function<void()>, const ErrorLevel) {
        called = true;
    });

errorHandler(Error::kTEST__ASSERT_CALLED);
ASSERT_TRUE(called);

Updated on 31 May 2022 at 15:29:15 CEST