#include <stdio.h>
#include <stdlib.h>
/* this demo is aim to make check exception as a piece of cake */
#define _SUCC 0
#define _FAIL (-1)
#define LOG_ERR printf
#define CHK_ERR_NE(_FUNC, _EXP, _RET) \
do \
{ \
if (_EXP != _RET) \
{ \
LOG_ERR("func=[%s], ret=[%d], caller=[%s], file=[%s], line=[%d] ***\n", \
#_FUNC, _RET, __func__, __FILE__, __LINE__); \
goto __EXCEPTION; \
} \
} while (0)
int foo()
{
return _FAIL;
}
int main()
{
int ret = 0;
ret = foo();
CHK_ERR_NE(foo, _SUCC, ret);
printf("Hello world!\n");
return _SUCC;
__EXCEPTION:
/* log other info: parameter value, temp var value, etc. */
/* check and release resources that allocated in this function */
printf("Hello world, exception!\n");
return _FAIL;
}
#include <stdlib.h>
/* this demo is aim to make check exception as a piece of cake */
#define _SUCC 0
#define _FAIL (-1)
#define LOG_ERR printf
#define CHK_ERR_NE(_FUNC, _EXP, _RET) \
do \
{ \
if (_EXP != _RET) \
{ \
LOG_ERR("func=[%s], ret=[%d], caller=[%s], file=[%s], line=[%d] ***\n", \
#_FUNC, _RET, __func__, __FILE__, __LINE__); \
goto __EXCEPTION; \
} \
} while (0)
int foo()
{
return _FAIL;
}
int main()
{
int ret = 0;
ret = foo();
CHK_ERR_NE(foo, _SUCC, ret);
printf("Hello world!\n");
return _SUCC;
__EXCEPTION:
/* log other info: parameter value, temp var value, etc. */
/* check and release resources that allocated in this function */
printf("Hello world, exception!\n");
return _FAIL;
}