Sometimes, when I program in C ++ / C, I end up calling the same function several times, and I was wondering what is the most efficient way to check for errors for all these calls? Using statements if elsetakes a lot of code and looks ugly. I came up with my own way to check for errors, maybe there is a better way that I should use.
int errs[5] = {0};
errs[0] = functiona(...);
errs[1] = functiona(...);
...
errs[5] = functiona(...);
for (int i = 0; i < 5; i++)
{
if (err[i] == 0)
MAYDAY!_wehaveanerror();
}
Note. I understand that using tryand catchmay be better for C ++, since it will solve this problem by throwing an exception on the first error, but the problem is that it is incompatible with a large number of functions that return error codes, such as the Windows API. Thank!