In the case of the following code structure:
int function_sequence(...)
{
f1(...);
f2(...);
f3(...);
f4(...);
f5(...);
return SUCCESS;
}
Which way of the error handling is more acceptable?
This:
int function_sequence(...)
{
if(f1(...)){
// Error handling
return ERROR;
}
if(f2(...)){
// Error handling
return ERROR;
}
...
return SUCCESS;
}
Or this:
int function_sequence(...)
{
if(f1(...)){
goto error;
}
if(f2(...)){
goto error;
}
...
return SUCCESS;
error:
// Error handling
return ERROR;
}
goto erroridiom it was corporate mandated coding style.