== Why is this an issue?

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

[source,cpp]
----
try {
  /* code that can throw: 42 */
} catch (int ex) { // Noncompliant
  if (ex == 42) {
    /*...*/
  }
}
----


=== Compliant solution

[source,cpp]
----
try {
  /* code that can throw: std::domain_error("User ID not found.") */
} catch (const std::domain_error& ex) {
  /*...*/
}
----


== Resources

* {cpp} Core Guidelines - https://github.com/isocpp/CppCoreGuidelines/blob/e49158a/CppCoreGuidelines.md#e14-use-purpose-designed-user-defined-types-as-exceptions-not-built-in-types[E.14: Use purpose-designed user-defined types as exceptions (not built-in types)]


ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

=== Message

Catch a type that inherit from "std::exception".


=== Highlighting

type of the variable in the catch clause


'''
== Comments And Links
(visible only on this page)

=== on 17 Aug 2016, 20:44:56 Ann Campbell wrote:
looks good [~alban.auzeill]

endif::env-github,rspecator-view[]
