Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qexception.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qexception.h"
5#include "QtCore/qshareddata.h"
6
7#if !defined(QT_NO_EXCEPTIONS) || defined(Q_QDOC)
8
10
86{
87}
88
90{
91 QException e = *this;
92 throw e;
93}
94
96{
97 return new QException(*this);
98}
99
101{
102public:
103 QUnhandledExceptionPrivate(std::exception_ptr exception) noexcept : exceptionPtr(exception) { }
104 std::exception_ptr exceptionPtr;
105};
106
116QUnhandledException::QUnhandledException(std::exception_ptr exception) noexcept
117 : d(new QUnhandledExceptionPrivate(exception))
118{
119}
120
126 : d(std::exchange(other.d, {}))
127{
128}
129
137
143{
144 d = other.d;
145 return *this;
146}
147
163std::exception_ptr QUnhandledException::exception() const
164{
165 return d->exceptionPtr;
166}
167
171
173{
174 QUnhandledException e = *this;
175 throw e;
176}
177
182
183#if !defined(Q_QDOC)
184
185namespace QtPrivate {
186
188{
190 try {
191 e.raise();
192 } catch (...) {
193 exceptionHolder = std::current_exception();
194 }
195}
196
197void ExceptionStore::setException(std::exception_ptr e)
198{
200 exceptionHolder = e;
201}
202
204{
205 return !!exceptionHolder;
206}
207
208std::exception_ptr ExceptionStore::exception() const
209{
210 return exceptionHolder;
211}
212
214{
215 if (hasException())
216 std::rethrow_exception(exceptionHolder);
217}
218
220{
222 std::rethrow_exception(exceptionHolder);
223}
224
225} // namespace QtPrivate
226
227#endif //Q_QDOC
228
230
231#endif // QT_NO_EXCEPTIONS
\inmodule QtCore
Definition qexception.h:22
virtual QException * clone() const
In your QException subclass, reimplement clone() like this:
virtual void raise() const
In your QException subclass, reimplement raise() like this:
~QException() noexcept
\inmodule QtCore
Definition qshareddata.h:19
QUnhandledExceptionPrivate(std::exception_ptr exception) noexcept
std::exception_ptr exceptionPtr
\inmodule QtCore
Definition qexception.h:31
QUnhandledException & operator=(const QUnhandledException &other) noexcept
Assigns other to this QUnhandledException object and returns a reference to this QUnhandledException ...
~QUnhandledException() noexcept override
QUnhandledException * clone() const override
void raise() const override
std::exception_ptr exception() const
QUnhandledException(std::exception_ptr exception=nullptr) noexcept
std::exception_ptr exceptionHolder
Definition qexception.h:64
std::exception_ptr exception() const
void setException(const QException &e)
Q_NORETURN void rethrowException() const
Combined button and popup list for selecting options.
\macro QT_NO_KEYWORDS >
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
QSharedPointer< T > other(t)
[5]