2 ms·
It's easier to get this right: { Resource foo(path); if … { return -ENOMEM } return 0; } Than to get this right:
by knorker 9y ago
It's easier to get this right:
{
Resource foo(path);
if … {
return -ENOMEM
}
return 0;
}
Than to get this right:
{
Resource* foo = acquire(path);
if … {
release(foo);
return -ENOMEM
}
release(foo);
return 0;
}
Even if you do the goto-style:
{
Resource* foo = acquire(path);
int rc = 0;
if … {
rc = -ENOMEM
goto out;
}
out:
release(foo);
return rc;
}