18 lines
661 B
Plaintext
18 lines
661 B
Plaintext
![]() |
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[]
|