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)
Move-构造一个 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 对象的引用。
© 2025 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.