QUnhandledException 类

QUnhandledException 类表示 Qt Concurrent 工作者线程中的未处理异常。 更多...

头: #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.

成员函数文档编制

[noexcept, 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 ().

[noexcept] QUnhandledException:: QUnhandledException (const QUnhandledException & other )

Constructs a QUnhandledException object as a copy of other .

[noexcept] 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 引入。

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

交换此 QUnhandledException with other 。此函数非常快且从不失败。

该函数在 Qt 6.0 引入。

[noexcept] QUnhandledException &QUnhandledException:: operator= (const QUnhandledException & other )

赋值 other 到此 QUnhandledException 对象并返回引用为此 QUnhandledException 对象。