aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsaturneric <[email protected]>2023-10-17 18:04:34 +0000
committersaturneric <[email protected]>2023-10-17 18:04:34 +0000
commit42163a07fa4a16c5f4501c96ceffcbc258913cd6 (patch)
tree0c99b7f35a675fb31822125e43f2294281b8fe52
parentfeat: imporve module system (diff)
downloadGpgFrontend-42163a07fa4a16c5f4501c96ceffcbc258913cd6.tar.gz
GpgFrontend-42163a07fa4a16c5f4501c96ceffcbc258913cd6.zip
feat: print stacktrace when exception caught
-rw-r--r--src/core/thread/Task.cpp19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/core/thread/Task.cpp b/src/core/thread/Task.cpp
index 1da18a86..e2d1138b 100644
--- a/src/core/thread/Task.cpp
+++ b/src/core/thread/Task.cpp
@@ -28,6 +28,7 @@
#include "core/thread/Task.h"
+#include <boost/stacktrace.hpp>
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
@@ -123,8 +124,17 @@ class Task::Impl : public QObject {
// build runnable package for running
auto runnable_package = [=, id = GetFullID()]() {
SPDLOG_DEBUG("task {} runnable start runing", id);
- // Run() will set rtn by itself
- Run();
+
+ try {
+ // Run() will set rtn by itself
+ parent_->Run();
+ } catch (std::exception &e) {
+ SPDLOG_ERROR("exception caught at task: {}", e.what());
+ SPDLOG_ERROR(
+ "exception stacktrace: {}",
+ boost::stacktrace::to_string(boost::stacktrace::stacktrace()));
+ }
+
// raise signal to anounce after runnable returned
if (run_callback_after_runnable_finished_)
emit parent_->SignalTaskRunnableEnd(rtn_);
@@ -227,7 +237,10 @@ class Task::Impl : public QObject {
}
}
} catch (std::exception &e) {
- SPDLOG_ERROR("exception caught: {}", e.what());
+ SPDLOG_ERROR("exception caught at task callback: {}", e.what());
+ SPDLOG_ERROR(
+ "exception stacktrace: {}",
+ boost::stacktrace::to_string(boost::stacktrace::stacktrace()));
} catch (...) {
SPDLOG_ERROR("unknown exception caught");
}