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 | #ifndef QTCORE_QEXCEPTION_H |
5 | #define QTCORE_QEXCEPTION_H |
6 | |
7 | #include <QtCore/qatomic.h> |
8 | #include <QtCore/qshareddata.h> |
9 | |
10 | #ifndef QT_NO_EXCEPTIONS |
11 | # include <exception> |
12 | #endif |
13 | |
14 | QT_REQUIRE_CONFIG(future); |
15 | |
16 | QT_BEGIN_NAMESPACE |
17 | |
18 | |
19 | #if !defined(QT_NO_EXCEPTIONS) || defined(Q_QDOC) |
20 | |
21 | class Q_CORE_EXPORT QException : public std::exception |
22 | { |
23 | public: |
24 | ~QException() noexcept; |
25 | virtual void raise() const; |
26 | virtual QException *clone() const; |
27 | }; |
28 | |
29 | class QUnhandledExceptionPrivate; |
30 | class Q_CORE_EXPORT QUnhandledException final : public QException |
31 | { |
32 | public: |
33 | QUnhandledException(std::exception_ptr exception = nullptr) noexcept; |
34 | ~QUnhandledException() noexcept override; |
35 | |
36 | QUnhandledException(QUnhandledException &&other) noexcept; |
37 | QUnhandledException(const QUnhandledException &other) noexcept; |
38 | |
39 | void swap(QUnhandledException &other) noexcept { d.swap(other.d); } |
40 | |
41 | QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_PURE_SWAP(QUnhandledException) |
42 | QUnhandledException &operator=(const QUnhandledException &other) noexcept; |
43 | |
44 | void raise() const override; |
45 | QUnhandledException *clone() const override; |
46 | |
47 | std::exception_ptr exception() const; |
48 | |
49 | private: |
50 | QSharedDataPointer<QUnhandledExceptionPrivate> d; |
51 | }; |
52 | |
53 | namespace QtPrivate { |
54 | |
55 | class Q_CORE_EXPORT ExceptionStore |
56 | { |
57 | public: |
58 | void setException(const QException &e); |
59 | void setException(std::exception_ptr e); |
60 | bool hasException() const; |
61 | std::exception_ptr exception() const; |
62 | void throwPossibleException(); |
63 | Q_NORETURN void rethrowException() const; |
64 | std::exception_ptr exceptionHolder; |
65 | }; |
66 | |
67 | } // namespace QtPrivate |
68 | |
69 | #else // QT_NO_EXCEPTIONS |
70 | |
71 | namespace QtPrivate { |
72 | |
73 | class Q_CORE_EXPORT ExceptionStore |
74 | { |
75 | public: |
76 | ExceptionStore() { } |
77 | inline void throwPossibleException() {} |
78 | inline void rethrowException() const { } |
79 | }; |
80 | |
81 | } // namespace QtPrivate |
82 | |
83 | #endif // QT_NO_EXCEPTIONS |
84 | |
85 | QT_END_NAMESPACE |
86 | |
87 | #endif |
88 | |