I have a scenario in the code where the following pattern exist -
if (!function(A))
{
log("this is the %d error in this file called %s", num, fileName);
throw AppException(FUNCTION_ERROR);
}
the issue with this is you need to do this all the time and the code looks really dirty. so I want to define a macro like -
#define VerifyOrThrow(b, retcode, logerror)
if (b == 0) \
{ \
log(logerror,arg1, arg2) -->this is the issue \
throw(AppException(retcode)); \
}
then I can use it like this in a single line
VerifyOrThrow(functionA(), FUNCTION_ERROR,this is the %d error in this file called %s);
The issue is I am not sure how to define the macro for the variable length argument for the log string.
Any ideas?