From https://clang.llvm.org/extra/clang-tidy/checks/bugprone/empty-catch.html
To avoid these issues, developers should always handle exceptions properly
This warning looks legit. I wonder if it can be resolved instead of suppressed.
I am unable to reproduce it, so I am probably doing something wrong. But this should resolve it, suggested from https://github.com/capnproto/capnproto/issues/553#issuecomment-328554603:
0--- i/include/mp/util.h
1+++ w/include/mp/util.h
2@@ -6,12 +6,13 @@
3 #define MP_UTIL_H
4
5 #include <capnp/schema.h>
6 #include <cstddef>
7 #include <functional>
8 #include <future>
9+#include <kj/debug.h>
10 #include <kj/common.h>
11 #include <kj/exception.h>
12 #include <kj/string-tree.h>
13 #include <memory>
14 #include <string.h>
15 #include <string>
16@@ -154,13 +155,14 @@ struct DestructorCatcher
17 T value;
18 template <typename... Params>
19 DestructorCatcher(Params&&... params) : value(kj::fwd<Params>(params)...)
20 {
21 }
22 ~DestructorCatcher() noexcept try {
23- } catch (const kj::Exception& e) { // NOLINT(bugprone-empty-catch)
24+ } catch (const kj::Exception& e) {
25+ KJ_LOG(ERROR, e);
26 }
27 };
28
29 //! Wrapper around callback function for compatibility with std::async.
30 //!
31 //! std::async requires callbacks to be copyable and requires noexcept
Further, unrelated to this PR, the DestructorCatcher does not seem to work in the first place:
0class A
1{
2public:
3 ~A()
4 {
5 throw std::runtime_error{"aaa"};
6 }
7};
8
9template <typename T>
10struct DestructorCatcher
11{
12 T value;
13 template <typename... Params>
14 DestructorCatcher(Params&&... params) : value(std::forward<Params>(params)...)
15 {
16 }
17 ~DestructorCatcher() noexcept try {
18 } catch (const std::runtime_error& e) {
19 // Does not work with or without a return.
20 //return;
21 }
22};
23
24int main(int, char**)
25{
26 try {
27 std::shared_ptr<DestructorCatcher<A>> p{std::make_shared<DestructorCatcher<A>>()};
28 } catch (const std::runtime_error& e) {
29 std::cout << "in main: " << e.what() << "\n";
30 }
31 return 0;
32}
0 * frame [#0](/bitcoin-core-multiprocess/0/): 0x0000000825ade18a libc.so.7`__sys_thr_kill at thr_kill.S:4
1 frame [#1](/bitcoin-core-multiprocess/1/): 0x0000000825a575a4 libc.so.7`__raise(s=6) at raise.c:50:10
2 frame [#2](/bitcoin-core-multiprocess/2/): 0x0000000825b0ab29 libc.so.7`abort at abort.c:64:8
3 frame [#3](/bitcoin-core-multiprocess/3/): 0x0000000000203c0e t`__clang_call_terminate + 14
4 frame [#4](/bitcoin-core-multiprocess/4/): 0x0000000000204e09 t`A::~A(this=0x00000e1f0581a038) at t.cc:184:15
5 frame [#5](/bitcoin-core-multiprocess/5/): 0x0000000000204db5 t`DestructorCatcher<A>::~DestructorCatcher(this=0x00000e1f0581a038) at t.cc:197:5
6 frame [#7](/bitcoin-core-multiprocess/7/): 0x0000000000204d59 t`void std::__1::allocator_traits<std::__1::allocator<DestructorCatcher<A>>>::destroy[abi:de180100]<DestructorCatcher<A>, void, void>((null)=0x00000008205e8697, __p=0x00000e1f0581a038) at allocator_traits.h:316:5
7 frame [#12](/bitcoin-core-multiprocess/12/): 0x0000000000203bf8 t`std::__1::shared_ptr<DestructorCatcher<A>>::~shared_ptr[abi:de180100](this=0x00000008205e8770) at shared_ptr.h:648:17
8 frame [#13](/bitcoin-core-multiprocess/13/): 0x0000000000203aaa t`main((null)=1, (null)=0x00000008205e8818) at t.cc:206:5