diff options
Diffstat (limited to 'src/corelib/thread/qexception.cpp')
-rw-r--r-- | src/corelib/thread/qexception.cpp | 55 |
1 files changed, 14 insertions, 41 deletions
diff --git a/src/corelib/thread/qexception.cpp b/src/corelib/thread/qexception.cpp index f9c63085b7..5c7a05c9c2 100644 --- a/src/corelib/thread/qexception.cpp +++ b/src/corelib/thread/qexception.cpp @@ -158,65 +158,38 @@ QUnhandledException *QUnhandledException::clone() const namespace QtPrivate { -class Base : public QSharedData -{ -public: - Base(QException *exception) - : exception(exception), hasThrown(false) { } - ~Base() { delete exception; } - - QException *exception; - bool hasThrown; -}; - -ExceptionHolder::ExceptionHolder(QException *exception) -: base(exception ? new Base(exception) : nullptr) {} - -ExceptionHolder::ExceptionHolder(const ExceptionHolder &other) -: base(other.base) -{} - -void ExceptionHolder::operator=(const ExceptionHolder &other) -{ - base = other.base; -} - -ExceptionHolder::~ExceptionHolder() -{} - -QException *ExceptionHolder::exception() const +void ExceptionStore::setException(const QException &e) { - if (!base) - return nullptr; - return base->exception; + Q_ASSERT(!hasException()); + try { + e.raise(); + } catch (...) { + exceptionHolder = std::current_exception(); + } } -void ExceptionStore::setException(const QException &e) +void ExceptionStore::setException(std::exception_ptr e) { - if (hasException() == false) - exceptionHolder = ExceptionHolder(e.clone()); + Q_ASSERT(!hasException()); + exceptionHolder = e; } bool ExceptionStore::hasException() const { - return (exceptionHolder.exception() != nullptr); + return !!exceptionHolder; } -ExceptionHolder ExceptionStore::exception() +std::exception_ptr ExceptionStore::exception() const { return exceptionHolder; } void ExceptionStore::throwPossibleException() { - if (hasException() ) { - exceptionHolder.base->hasThrown = true; - exceptionHolder.exception()->raise(); - } + if (hasException()) + std::rethrow_exception(exceptionHolder); } -bool ExceptionStore::hasThrown() const { return exceptionHolder.base->hasThrown; } - } // namespace QtPrivate #endif //Q_CLANG_QDOC |