Throwing as an exception an object that is not derived from std::exception
is a bad practice. It is usually unreliable, meaningless,
and a source of type clashes.
For the same reason, catching a non-exception type is a sign that your application has a bad exception-handling design. You should use standard
exception types or create your own exception types that inherit at some level from std::exception
.
Noncompliant code example
try {
/* code that can throw: 42 */
} catch (int ex) { // Noncompliant
if (ex == 42) {
/*...*/
}
}
Compliant solution
try {
/* code that can throw: std::domain_error("User ID not found.") */
} catch (const std::domain_error& ex) {
/*...*/
}