From fa1d0e59954873403c897ffbb996b01d1faeffd2 Mon Sep 17 00:00:00 2001 From: Bjarne Stroustrup Date: Wed, 17 May 2017 14:25:13 -0400 Subject: [PATCH] exceptionsand const Added to E.15 --- CppCoreGuidelines.md | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/CppCoreGuidelines.md b/CppCoreGuidelines.md index aedefc4..53c3156 100644 --- a/CppCoreGuidelines.md +++ b/CppCoreGuidelines.md @@ -14139,10 +14139,16 @@ To prevent slicing. // ... } -Instead, use: +Instead, use a reference: catch (exception& e) { /* ... */ } +of - typically better stil - a `const` reference: + + catch (const exception& e) { /* ... */ } + +Most handlers do not modify their exception and in general we [recommend use of `const`](#Res-const). + ##### Enforcement Flag by-value exceptions if their types are part of a hierarchy (could require whole-program analysis to be perfect).