1 .. title:: clang-tidy - misc-throw-by-value-catch-by-reference
3 misc-throw-by-value-catch-by-reference
4 ======================================
6 `cert-err09-cpp` redirects here as an alias for this check.
7 `cert-err61-cpp` redirects here as an alias for this check.
9 Finds violations of the rule "Throw by value, catch by reference" presented for
10 example in "C++ Coding Standards" by H. Sutter and A. Alexandrescu, as well as
11 the CERT C++ Coding Standard rule `ERR61-CPP. Catch exceptions by lvalue reference
12 <https://wiki.sei.cmu.edu/confluence/display/cplusplus/ERR61-CPP.+Catch+exceptions+by+lvalue+reference>`_.
16 * Throwing string literals will not be flagged despite being a pointer. They
17 are not susceptible to slicing and the usage of string literals is
19 * Catching character pointers (``char``, ``wchar_t``, unicode character types)
20 will not be flagged to allow catching string literals.
21 * Moved named values will not be flagged as not throwing an anonymous
22 temporary. In this case we can be sure that the user knows that the object
23 can't be accessed outside catch blocks handling the error.
24 * Throwing function parameters will not be flagged as not throwing an
25 anonymous temporary. This allows helper functions for throwing.
26 * Re-throwing caught exception variables will not be flagged as not throwing
27 an anonymous temporary. Although this can usually be done by just writing
28 ``throw;`` it happens often enough in real code.
33 .. option:: CheckThrowTemporaries
35 Triggers detection of violations of the CERT recommendation ERR09-CPP. Throw
36 anonymous temporaries.
39 .. option:: WarnOnLargeObject
41 Also warns for any large, trivial object caught by value. Catching a large
42 object by value is not dangerous but affects the performance negatively. The
43 maximum size of an object allowed to be caught without warning can be set
44 using the `MaxSize` option.
49 Determines the maximum size of an object allowed to be caught without
50 warning. Only applicable if :option:`WarnOnLargeObject` is set to `true`. If
51 the option is set by the user to `std::numeric_limits<uint64_t>::max()` then
52 it reverts to the default value.
53 Default is the size of `size_t`.