FNFT
Files | Macros | Functions
PRIVATE: Macros for raising errors and warnings

This module contains macros that can be used to raise errors and warnings.

Most FNFT functions return one of the error codes defined in the module Error codes. The return type should be FNFT_INT. The error should be risen using the corresponding macro from this group. By using these macros, error messages will be printed. The macro returns the corresponding error code. For example:

if (pointer == NULL)
return FNFT__E_NOMEM;

The function that prints the errors can be changed using fnft_errwarn_setprintf. More...

Files

file  fnft__errwarn.h
 

Macros

#define FNFT__WARN(msg)   fnft__warn_aux(__func__, __LINE__, msg);
 
#define FNFT__E_NOMEM   FNFT__ERRMSG(FNFT_EC_NOMEM, "Out of memory.")
 
#define FNFT__E_INVALID_ARGUMENT(name)   FNFT__ERRMSG(FNFT_EC_INVALID_ARGUMENT, FNFT__E_INVALID_ARGUMENT_(name))
 
#define FNFT__E_SUBROUTINE(ec)   FNFT__ERRMSG(-abs(ec), "Subroutine failure.")
 
#define FNFT__E_DIV_BY_ZERO   FNFT__ERRMSG(FNFT_EC_DIV_BY_ZERO, "Division by zero.")
 
#define FNFT__E_TEST_FAILED   FNFT__ERRMSG(FNFT_EC_TEST_FAILED, "Test failed.")
 
#define FNFT__E_OTHER(msg)   FNFT__ERRMSG(FNFT_EC_OTHER, msg)
 
#define FNFT__E_NOT_YET_IMPLEMENTED(name, msg)   FNFT__ERRMSG(FNFT_EC_NOT_YET_IMPLEMENTED, FNFT__E_NOT_YET_IMPLEMENTED_(name,msg))
 
#define FNFT__E_SANITY_CHECK_FAILED(msg)   FNFT__ERRMSG(FNFT_EC_SANITY_CHECK_FAILED, FNFT__E_SANITY_CHECK_FAILED_(msg))
 
#define FNFT__E_ASSERTION_FAILED   FNFT__ERRMSG(FNFT_EC_ASSERTION_FAILED, "Assertion failed.")
 
#define FNFT__CHECK_RETCODE(ret_code, label)   {if (ret_code!=FNFT_SUCCESS) {ret_code=FNFT__E_SUBROUTINE(ret_code);goto label;}}
 
#define FNFT__ERRMSG(ec, msg)   fnft__errmsg_aux(ec, __func__, __LINE__, msg);
 
#define FNFT__E_INVALID_ARGUMENT_(name)   "Invalid argument "#name"."
 
#define FNFT__E_NOT_YET_IMPLEMENTED_(name, msg)   "Not yet implemented ("#name"). "#msg
 
#define FNFT__E_SANITY_CHECK_FAILED_(msg)   "Sanity check failed ("#msg")."
 

Functions

FNFT_INT fnft__errmsg_aux (const FNFT_INT ec, const char *func, const FNFT_INT line, const char *msg)
 
void fnft__warn_aux (const char *func, const FNFT_INT line, const char *msg)
 

Detailed Description

This module contains macros that can be used to raise errors and warnings.

Most FNFT functions return one of the error codes defined in the module Error codes. The return type should be FNFT_INT. The error should be risen using the corresponding macro from this group. By using these macros, error messages will be printed. The macro returns the corresponding error code. For example:

if (pointer == NULL)
return FNFT__E_NOMEM;

The function that prints the errors can be changed using fnft_errwarn_setprintf.

Macro Definition Documentation

◆ FNFT__CHECK_RETCODE

#define FNFT__CHECK_RETCODE (   ret_code,
  label 
)    {if (ret_code!=FNFT_SUCCESS) {ret_code=FNFT__E_SUBROUTINE(ret_code);goto label;}}

Macro for checking if a return code indicates an error. If ret_code!=FNFT_SUCCESS, a subroutine error is risen and the macro uses goto to jump to label.

◆ FNFT__E_ASSERTION_FAILED

#define FNFT__E_ASSERTION_FAILED   FNFT__ERRMSG(FNFT_EC_ASSERTION_FAILED, "Assertion failed.")

Macro for raising an assertion check failed error.

◆ FNFT__E_DIV_BY_ZERO

#define FNFT__E_DIV_BY_ZERO   FNFT__ERRMSG(FNFT_EC_DIV_BY_ZERO, "Division by zero.")

Macro for raising an division by zero error.

◆ FNFT__E_INVALID_ARGUMENT

#define FNFT__E_INVALID_ARGUMENT (   name)    FNFT__ERRMSG(FNFT_EC_INVALID_ARGUMENT, FNFT__E_INVALID_ARGUMENT_(name))

Macro for raising an invalid argument error.

◆ FNFT__E_INVALID_ARGUMENT_

#define FNFT__E_INVALID_ARGUMENT_ (   name)    "Invalid argument "#name"."

Auxiliary macro that is used to stringify the input to FNFT__E_INVALID_ARGUMENT. Do not call directly.

◆ FNFT__E_NOMEM

#define FNFT__E_NOMEM   FNFT__ERRMSG(FNFT_EC_NOMEM, "Out of memory.")

Macro for raising an out of memory error.

◆ FNFT__E_NOT_YET_IMPLEMENTED

#define FNFT__E_NOT_YET_IMPLEMENTED (   name,
  msg 
)    FNFT__ERRMSG(FNFT_EC_NOT_YET_IMPLEMENTED, FNFT__E_NOT_YET_IMPLEMENTED_(name,msg))

Macro for raising a not yet implemented error, where name is an identifier for the feature and msg is an additional custom error message.

◆ FNFT__E_NOT_YET_IMPLEMENTED_

#define FNFT__E_NOT_YET_IMPLEMENTED_ (   name,
  msg 
)    "Not yet implemented ("#name"). "#msg

Auxiliary macro used to stringify the input to FNFT__E_NOT_YET_IMPLEMENTED. Do not call directly.

◆ FNFT__E_OTHER

#define FNFT__E_OTHER (   msg)    FNFT__ERRMSG(FNFT_EC_OTHER, msg)

Macro for raising an unspecified error, where msg is a custom error message.

◆ FNFT__E_SANITY_CHECK_FAILED

#define FNFT__E_SANITY_CHECK_FAILED (   msg)    FNFT__ERRMSG(FNFT_EC_SANITY_CHECK_FAILED, FNFT__E_SANITY_CHECK_FAILED_(msg))

Macro for raising a sanity check failed error, where msg is a custom error message.

◆ FNFT__E_SANITY_CHECK_FAILED_

#define FNFT__E_SANITY_CHECK_FAILED_ (   msg)    "Sanity check failed ("#msg")."

Auxiliary macro used to stringify the input to FNFT__E_NOT_YET_IMPLEMENTED. Do not call directly.

◆ FNFT__E_SUBROUTINE

#define FNFT__E_SUBROUTINE (   ec)    FNFT__ERRMSG(-abs(ec), "Subroutine failure.")

Macro for raising an subroutine error, where ec is the error code returned by the subroutine. The error code returned by this macro is -abs(ec). Since all other error codes are positive, a negative error code therefore indicates that a subroutine failed with the error code abs(ec).

◆ FNFT__E_TEST_FAILED

#define FNFT__E_TEST_FAILED   FNFT__ERRMSG(FNFT_EC_TEST_FAILED, "Test failed.")

Macro for raising a test failed error.

◆ FNFT__ERRMSG

#define FNFT__ERRMSG (   ec,
  msg 
)    fnft__errmsg_aux(ec, __func__, __LINE__, msg);

Macro that prints the given error message using fnft__errmsg_aux and returns the error code ec. Auxiliary macro. Do not call directly.

◆ FNFT__WARN

#define FNFT__WARN (   msg)    fnft__warn_aux(__func__, __LINE__, msg);

Provides a warning message to the user.

Function Documentation

◆ fnft__errmsg_aux()

FNFT_INT fnft__errmsg_aux ( const FNFT_INT  ec,
const char *  func,
const FNFT_INT  line,
const char *  msg 
)

Auxiliary function that prints a formated error message using the printf function returned by fnft_errwarn_getprintf. It simply returns the error code ec. Do not call directly.

◆ fnft__warn_aux()

void fnft__warn_aux ( const char *  func,
const FNFT_INT  line,
const char *  msg 
)

Auxiliary function that prints a formated warning message using the printf function returned by fnft_errwarn_getprintf. Do not call directly.