32 lines · plain
1.. title:: clang-tidy - bugprone-exception-copy-constructor-throws2 3bugprone-exception-copy-constructor-throws4==========================================5 6Checks whether a thrown object's copy constructor can throw.7 8Exception objects are required to be copy constructible in C++. However, an9exception's copy constructor should not throw to avoid potential issues when10unwinding the stack. If an exception is thrown during stack unwinding (such11as from a copy constructor of an exception object), the program will12terminate via ``std::terminate``.13 14.. code-block:: c++15 16 class SomeException {17 public:18 SomeException() = default;19 SomeException(const SomeException&) { /* may throw */ }20 };21 22 void f() {23 throw SomeException(); // warning: thrown exception type's copy constructor can throw24 }25 26References27----------28 29This check corresponds to the CERT C++ Coding Standard rule30`ERR60-CPP. Exception objects must be nothrow copy constructible31<https://wiki.sei.cmu.edu/confluence/display/cplusplus/ERR60-CPP.+Exception+objects+must+be+nothrow+copy+constructible>`_.32