mardi 24 mars 2015

Alternative to goto-statement in this case? [duplicate]



This question already has an answer here:




Currently I am using gotos for closing handles and general cleanup if an error occurs.

Since I don't want to nest all the ifs and a function for cleanup would require a return besides the cleanup(); call, I don't have any good ideas left.


The structure is like so:



if (condition1) {
goto cleanup;
}

if (condition2) {
goto cleanup;
}

if (condition3) {
goto cleanup;
}

// do stuff only if all checks passed

cleanup:
CloseHandle(x);
CloseHandle(y);
// etc.




Aucun commentaire:

Enregistrer un commentaire