exceptionsand const

Added to E.15
This commit is contained in:
Bjarne Stroustrup 2017-05-17 14:25:13 -04:00
parent 81493f331c
commit fa1d0e5995

View File

@ -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).