From 4c793e6353ece51d4c04373f54e13d540b45195e Mon Sep 17 00:00:00 2001 From: Sona Kurazyan Date: Fri, 16 Oct 2020 12:25:13 +0200 Subject: Store std::exception_ptr in QUnhandledException For historical reasons Qt Concurrent reports QUnhandledException in case if an exception that is not derived from QException is thrown from a worker thread. Changing this behavior may not be a good idea, since the existing user code may rely on it. Changed QUnhandledException to wrap the std::exception_ptr to the actual exception, so that the users can obtain the information about the thrown exception if needed. [ChangeLog][QtCore][QUnhandledException] Improved QUnhandledException to store the std::exception_ptr to the actual exception thrown from a QtCocnurrent worker thread. Change-Id: I30e7c1d3e01aff6e1ed9938c421da0a888f12066 Reviewed-by: Fabian Kosmale --- .../doc/snippets/code/src_corelib_thread_qexception.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src/corelib/doc/snippets/code') diff --git a/src/corelib/doc/snippets/code/src_corelib_thread_qexception.cpp b/src/corelib/doc/snippets/code/src_corelib_thread_qexception.cpp index 723c1630f6..08bbee7dd3 100644 --- a/src/corelib/doc/snippets/code/src_corelib_thread_qexception.cpp +++ b/src/corelib/doc/snippets/code/src_corelib_thread_qexception.cpp @@ -83,3 +83,19 @@ void MyException::raise() const { throw *this; } MyException *MyException::clone() const { return new MyException(*this); } //! [3] + +//! [4] + +try { + auto f = QtConcurrent::run([] { throw MyException {}; }); + // ... +} catch (const QUnhandledException &e) { + try { + if (e.exception()) + std::rethrow_exception(e.exception()); + } catch (const MyException &ex) { + // Process 'ex' + } +} + +//! [4] -- cgit v1.2.3