42563aeaee30d9d49df71c7a8e81a2c6a96c1dd5
[platform/upstream/llvm.git] / clang-tools-extra / docs / clang-tidy / checks / hicpp-exception-baseclass.rst
1 .. title:: clang-tidy - hicpp-exception-baseclass
2
3 hicpp-exception-baseclass
4 =========================
5
6 Ensure that every value that in a ``throw`` expression is an instance of 
7 ``std::exception``.
8
9 This enforces `rule 15.1 <http://www.codingstandard.com/section/15-1-throwing-an-exception/>`_
10 of the High Integrity C++ Coding Standard.
11
12 .. code-block:: c++
13
14   class custom_exception {};
15
16   void throwing() noexcept(false) {
17     // Problematic throw expressions.
18     throw int(42);
19     throw custom_exception();
20   }
21
22   class mathematical_error : public std::exception {};
23
24   void throwing2() noexcept(false) {
25     // These kind of throws are ok.
26     throw mathematical_error();
27     throw std::runtime_error();
28     throw std::exception();
29   }
30