QUnhandledException Class
QUnhandledException 类表示Qt Concurrent 工作线程中未处理的异常。更多内容...
| 头文件: | #include <QUnhandledException> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
| qmake: | QT += core |
| 继承自: | QException |
公共函数
(since 6.0) | QUnhandledException(std::__exception_ptr::exception_ptr exception = nullptr) |
| QUnhandledException(const QUnhandledException &other) | |
| QUnhandledException(QUnhandledException &&other) | |
(since 6.0) std::__exception_ptr::exception_ptr | exception() const |
(since 6.0) void | swap(QUnhandledException &other) |
| QUnhandledException & | operator=(const QUnhandledException &other) |
详细说明
如果一个工作线程抛出一个不是QException 子类的异常,则 Qt Concurrent 这些函数将在接收线程一侧抛出一个 QUnhandledException。关于已抛出的实际异常的信息将保存在 QUnhandledException 类中,并可通过调用exception() 方法获取。例如,您可以通过以下方式处理由 QUnhandledException 持有的异常:
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'
}
}不支持从该类继承。
成员函数文档
[noexcept, since 6.0] QUnhandledException::QUnhandledException(std::__exception_ptr::exception_ptr exception = nullptr)
创建一个新的 QUnhandledException 对象。如果传入了 `exception `,则保存指向实际异常对象的指针。
该函数在 Qt 6.0 中引入。
另请参阅 exception()。
[noexcept] QUnhandledException::QUnhandledException(const QUnhandledException &other)
创建一个 QUnhandledException 对象,作为other 的副本。
[noexcept] QUnhandledException::QUnhandledException(QUnhandledException &&other)
将 QUnhandledException 进行移动构造,使其指向与other 所指向的相同对象。
[since 6.0] std::__exception_ptr::exception_ptr QUnhandledException::exception() const
返回指向保存在该QUnhandledException 中的实际异常的指针。如果该指针不指向异常对象,则返回null 指针。
该函数在 Qt 6.0 中引入。
[noexcept, since 6.0] void QUnhandledException::swap(QUnhandledException &other)
将此未处理的异常对象与other 进行交换。此操作速度极快,且绝不会失败。
该函数在 Qt 6.0 中引入。
[noexcept] QUnhandledException &QUnhandledException::operator=(const QUnhandledException &other)
将other 赋值给此QUnhandledException 对象,并返回对此QUnhandledException 对象的引用。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.