Rethrowing an unmodified copy of the caught exception is a waste of resources. Additionally, doing so may lead to a loss of precision in the object type and its data, since the copy will be an instance of the base class, rather than of the potentially more specific exception class originally caught.


== Noncompliant Code Example

----
try {
  throw std::invalid_argument("x");
} catch (const std::exception& ex) {
  /* ... */
  throw ex; // Noncompliant; the received "std::invalid_argument" is copied into a less specialized class "std::exception"
}
----


== Compliant Solution

----
try {
  throw std::invalid_argument("x");
} catch (const std::exception& ex) {
  /* ... */
  throw; // rethrows the initial "std::invalid_argument"
}
----



ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)

include::comments-and-links.adoc[]
endif::env-github,rspecator-view[]
