From 9ac22abe0a3697d75e5342c5e3c424f399a44958 Mon Sep 17 00:00:00 2001 From: Andrew Pardoe Date: Mon, 26 Mar 2018 12:03:46 -0700 Subject: [PATCH] Adding note suggested by @jwakely in #1165 --- CppCoreGuidelines.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index 881cc5a..98b511f 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -15273,6 +15273,10 @@ of - typically better still - a `const` reference: Most handlers do not modify their exception and in general we [recommend use of `const`](#Res-const). +##### Note + +To rethrow a caught exception use `throw;` not `throw e;`. Using `throw e;` would throw a new copy of `e` (sliced to the static type `std::exception`) instead of rethrowing the original exception of type `std::runtime_error`. (But keep [Don't try to catch every exception in every function](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Re-not-always) and [Minimize the use of explicit `try`/`catch`](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#Re-catch) in mind.) + ##### Enforcement Flag by-value exceptions if their types are part of a hierarchy (could require whole-program analysis to be perfect).