xref: /llvm-project/clang-tools-extra/docs/clang-tidy/checks/hicpp/exception-baseclass.rst (revision c6fa07ca966eb8902465adbe2c6c1e41a108881c)
1.. title:: clang-tidy - hicpp-exception-baseclass
2
3hicpp-exception-baseclass
4=========================
5
6Ensure that every value that in a ``throw`` expression is an instance of
7``std::exception``.
8
9This enforces `rule 15.1 <https://www.perforce.com/resources/qac/high-integrity-cpp-coding-standard-exception-handling>`_
10of 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