Debian Codegraph @

clang-tools-extra/docs/clang-tidy/checks/bugprone/exception-escape.rst

raw
1 .. title:: clang-tidy - bugprone-exception-escape
2
3 bugprone-exception-escape
4 =========================
5
6 Finds functions which may throw an exception directly or indirectly, but they
7 should not. The functions which should not throw exceptions are the following:
8
9 * Destructors
10 * Move constructors
11 * Move assignment operators
12 * The ``main()`` functions
13 * ``swap()`` functions
14 * ``iter_swap()`` functions
15 * ``iter_move()`` functions
16 * Functions marked with ``throw()`` or ``noexcept``
17 * Other functions given as option
18
19 A destructor throwing an exception may result in undefined behavior, resource
20 leaks or unexpected termination of the program. Throwing move constructor or
21 move assignment also may result in undefined behavior or resource leak. The
22 ``swap()`` operations expected to be non throwing most of the cases and they
23 are always possible to implement in a non throwing way. Non throwing ``swap()``
24 operations are also used to create move operations. A throwing ``main()``
25 function also results in unexpected termination.
26
27 Functions declared explicitly with ``noexcept(false)`` or ``throw(exception)``
28 will be excluded from the analysis, as even though it is not recommended for
29 functions like ``swap()``, ``main()``, move constructors, move assignment operators
30 and destructors, it is a clear indication of the developer's intention and
31 should be respected.
32
33 WARNING! This check may be expensive on large source files.
34
35 Options
36 -------
37
38 .. option:: FunctionsThatShouldNotThrow
39
40 Comma separated list containing function names which should not throw. An
41 example value for this parameter can be ``WinMain`` which adds function
42 ``WinMain()`` in the Windows API to the list of the functions which should
43 not throw. Default value is an empty string.
44
45 .. option:: IgnoredExceptions
46
47 Comma separated list containing type names which are not counted as thrown
48 exceptions in the check. Default value is an empty string.