rspec/rules/S112/cfamily/rule.adoc

18 lines
661 B
Plaintext
Raw Normal View History

2020-06-30 10:16:44 +02:00
If you throw a general exception type, such as <code>std::exception</code>, <code>std::logic_error</code> or <code>std::runtime_error</code>, it forces consumers to catch all exceptions, including unknown exceptions they don't necessarily know how to handle.
Instead, either throw a subtype that already exists ( for example in <code><stdexcept></code> ), or create your own type that derives from a standard one.
== Noncompliant Code Example
----
throw std::logic_error("Unexpected null 'user_id' argument."); // Noncompliant
----
== Compliant Solution
----
throw std::invalid_argument("Unexpected null 'user_id' argument.");
----
include::../see.adoc[]