Error handling
E.19
Use a `final_action` object to express cleanup if no suitable resource handle is available
Reason
finally from the GSL is less verbose and harder to get wrong than try/catch.
Example
void f(int n)
{
void* p = malloc(n);
auto _ = gsl::finally([p] { free(p); });
// ...
}
Note
finally is not as messy as try/catch, but it is still ad-hoc. Prefer proper resource management objects. Consider finally a last resort.
Note
Use of finally is a systematic and reasonably clean alternative to the old goto exit; technique for dealing with cleanup where resource management is not systematic.
Enforcement
Heuristic: Detect goto exit;