QUnhandledException 類

The QUnhandledException class represents an unhandled exception in a Qt Concurrent worker thread. 更多...

頭: #include <QUnhandledException>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core
繼承: QException

公共函數

QUnhandledException (std::exception_ptr exception = nullptr)
QUnhandledException (const QUnhandledException & other )
QUnhandledException (QUnhandledException && other )
std::exception_ptr exception () const
void swap (QUnhandledException & other )
QUnhandledException & operator= (const QUnhandledException & other )

詳細描述

If a worker thread throws an exception that is not a subclass of QException Qt Concurrent functions will throw a QUnhandledException on the receiver thread side. The information about the actual exception that has been thrown will be saved in the QUnhandledException class and can be obtained using the exception () method. For example, you can process the exception held by QUnhandledException in the following way:

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'
    }
}
					

Inheriting from this class is not supported.

成員函數文檔編製

[since 6.0] QUnhandledException:: QUnhandledException ( std::exception_ptr exception = nullptr)

Constructs a new QUnhandledException object. Saves the pointer to the actual exception object if exception 被傳遞。

該函數在 Qt 6.0 引入。

另請參閱 exception ().

QUnhandledException:: QUnhandledException (const QUnhandledException & other )

Constructs a QUnhandledException object as a copy of other .

QUnhandledException:: QUnhandledException ( QUnhandledException && other )

Move-constructs a QUnhandledException, making it point to the same object as other 所指嚮的。

[since 6.0] std::exception_ptr QUnhandledException:: exception () const

返迴 pointer to the actual exception that has been saved in this QUnhandledException 。返迴 null pointer, if it does not point to an exception object.

該函數在 Qt 6.0 引入。

[since 6.0] void QUnhandledException:: swap ( QUnhandledException & other )

交換此 QUnhandledException with other 。此函數非常快且從不失敗。

該函數在 Qt 6.0 引入。

QUnhandledException &QUnhandledException:: operator= (const QUnhandledException & other )

賦值 other 到此 QUnhandledException 對象並返迴引用為此 QUnhandledException 對象。