Error handling
E.3
Use exceptions for error handling only
Reason
To keep error handling separated from "ordinary code." C++ implementations tend to be optimized based on the assumption that exceptions are rare.
Example, don't
// don't: exception not used for error handling
int find_index(vector<string>& vec, const string& x)
{
try {
for (gsl::index i = 0; i < vec.size(); ++i)
if (vec[i] == x) throw i; // found x
}
catch (int i) {
return i;
}
return -1; // not found
}
This is more complicated and most likely runs much slower than the obvious alternative. There is nothing exceptional about finding a value in a vector.
Enforcement
Would need to be heuristic. Look for exception values "leaked" out of catch clauses.