115 lines
4.7 KiB
C++
115 lines
4.7 KiB
C++
/**
|
|
* @file include/ActivMiddleware/ActivBase/StatusCodeException.h
|
|
*
|
|
* @brief Header file for the StatusCode exception class.
|
|
*/
|
|
|
|
#if (!defined ACTIV_BASE_STATUS_CODE_EXCEPTION_H)
|
|
#define ACTIV_BASE_STATUS_CODE_EXCEPTION_H
|
|
|
|
#include "ActivMiddleware/ActivBase/Exception.h"
|
|
|
|
//! Activ namespace.
|
|
namespace Activ
|
|
{
|
|
|
|
/**
|
|
* @brief Throw result if result of expression tests true using operator against statusCode.
|
|
*/
|
|
#define ACTIV_THROW_RESULT_IF(statusCode, operator, expression) \
|
|
do \
|
|
{ \
|
|
const ::Activ::StatusCode thisIsTheResultOfTheCall = expression; \
|
|
if (ACTIV_UNLIKELY(statusCode operator thisIsTheResultOfTheCall)) \
|
|
ACTIV_THROW(::Activ::StatusCodeException, thisIsTheResultOfTheCall); \
|
|
} \
|
|
while (false)
|
|
|
|
/**
|
|
* @brief Throw result if result of expression tests true using operator against statusCode1 and statusCode2.
|
|
*/
|
|
#define ACTIV_THROW_RESULT_IF_AND_IF(statusCode1, statusCode2, operator, expression) \
|
|
do \
|
|
{ \
|
|
const ::Activ::StatusCode thisIsTheResultOfTheCall = expression; \
|
|
if ((statusCode1 operator thisIsTheResultOfTheCall) && (statusCode2 operator thisIsTheResultOfTheCall)) \
|
|
ACTIV_THROW(::Activ::StatusCodeException, thisIsTheResultOfTheCall); \
|
|
} \
|
|
while (false)
|
|
|
|
/**
|
|
* @brief Throw result if result of expression tests true using operator against statusCode1 or statusCode2.
|
|
*/
|
|
#define ACTIV_THROW_RESULT_IF_OR_IF(statusCode1, statusCode2, operator, expression) \
|
|
do \
|
|
{ \
|
|
const ::Activ::StatusCode thisIsTheResultOfTheCall = expression; \
|
|
if ((statusCode1 operator thisIsTheResultOfTheCall) || (statusCode2 operator thisIsTheResultOfTheCall)) \
|
|
ACTIV_THROW(::Activ::StatusCodeException, thisIsTheResultOfTheCall); \
|
|
} \
|
|
while (false)
|
|
|
|
/**
|
|
* @brief Throw result with an message if result of expression tests true using operator against statusCode.
|
|
*/
|
|
#define ACTIV_THROW_RESULT_WITH_MESSAGE_IF(statusCode, operator, expression, message) \
|
|
do \
|
|
{ \
|
|
const ::Activ::StatusCode thisIsTheResultOfTheCall = expression; \
|
|
if (ACTIV_UNLIKELY(statusCode operator thisIsTheResultOfTheCall)) \
|
|
ACTIV_THROW_WITH_MESSAGE(::Activ::StatusCodeException, thisIsTheResultOfTheCall, message); \
|
|
} \
|
|
while (false)
|
|
|
|
/**
|
|
* @brief Throw result with a message if result of expression tests true using operator against statusCode1 and statusCode2.
|
|
*/
|
|
#define ACTIV_THROW_RESULT_WITH_MESSAGE_IF_AND_IF(statusCode1, statusCode2, operator, expression, message) \
|
|
do \
|
|
{ \
|
|
const ::Activ::StatusCode thisIsTheResultOfTheCall = expression; \
|
|
if ((statusCode1 operator thisIsTheResultOfTheCall) && (statusCode2 operator thisIsTheResultOfTheCall)) \
|
|
ACTIV_THROW_WITH_MESSAGE(::Activ::StatusCodeException, thisIsTheResultOfTheCall, message); \
|
|
} \
|
|
while (false)
|
|
|
|
/**
|
|
* @brief Throw result with message if result of expression tests true using operator against statusCode1 or statusCode2.
|
|
*/
|
|
#define ACTIV_THROW_RESULT_WITH_MESSAGE_IF_OR_IF(statusCode1, statusCode2, operator, expression, message) \
|
|
do \
|
|
{ \
|
|
const ::Activ::StatusCode thisIsTheResultOfTheCall = expression; \
|
|
if ((statusCode1 operator thisIsTheResultOfTheCall) || (statusCode2 operator thisIsTheResultOfTheCall)) \
|
|
ACTIV_THROW_WITH_MESSAGE(::Activ::StatusCodeException, thisIsTheResultOfTheCall, message); \
|
|
} \
|
|
while (false)
|
|
|
|
|
|
// ---------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
/**
|
|
* @brief StatusCode exception class.
|
|
*/
|
|
class StatusCodeException : public Exception
|
|
{
|
|
public:
|
|
/**
|
|
* @brief Constructor.
|
|
*
|
|
* @param file the file which raised the exception.
|
|
* @param function the function which raised the exception.
|
|
* @param line the line number which raised the exception.
|
|
* @param errorCode the exception specific error code, in this case a StatusCode value.
|
|
* @param message the exception message.
|
|
*/
|
|
ACTIV_BASE_API StatusCodeException(const char *file, const char *function, const uint_fast32_t line,
|
|
const uint_fast32_t errorCode, const String &message = "");
|
|
|
|
ACTIV_BASE_API virtual String ToString() const ACTIV_OVERRIDE;
|
|
};
|
|
|
|
} // namespace Activ
|
|
|
|
#endif // (!defined ACTIV_BASE_STATUS_CODE_EXCEPTION_H)
|