1 | // Copyright (C) 2022 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 QEXCEPTIONHANDLING_H |
5 | #define QEXCEPTIONHANDLING_H |
6 | |
7 | #include <QtCore/qtconfigmacros.h> |
8 | #include <QtCore/qcompilerdetection.h> |
9 | #include <QtCore/qtcoreexports.h> |
10 | |
11 | #if 0 |
12 | #pragma qt_class(QtExceptionHandling) |
13 | #pragma qt_sync_stop_processing |
14 | #endif |
15 | |
16 | QT_BEGIN_NAMESPACE |
17 | |
18 | /* These wrap try/catch so we can switch off exceptions later. |
19 | |
20 | Beware - do not use more than one QT_CATCH per QT_TRY, and do not use |
21 | the exception instance in the catch block. |
22 | If you can't live with those constraints, don't use these macros. |
23 | Use the QT_NO_EXCEPTIONS macro to protect your code instead. |
24 | */ |
25 | Q_NORETURN Q_DECL_COLD_FUNCTION Q_CORE_EXPORT void qTerminate() noexcept; |
26 | #ifdef QT_NO_EXCEPTIONS |
27 | # define QT_TRY if (true) |
28 | # define QT_CATCH(A) else |
29 | # define QT_THROW(A) qt_noop() |
30 | # define QT_RETHROW qt_noop() |
31 | # define QT_TERMINATE_ON_EXCEPTION(expr) do { expr; } while (false) |
32 | #else |
33 | # define QT_TRY try |
34 | # define QT_CATCH(A) catch (A) |
35 | # define QT_THROW(A) throw A |
36 | # define QT_RETHROW throw |
37 | # ifdef Q_COMPILER_NOEXCEPT |
38 | # define QT_TERMINATE_ON_EXCEPTION(expr) do { expr; } while (false) |
39 | # else |
40 | # define QT_TERMINATE_ON_EXCEPTION(expr) do { try { expr; } catch (...) { qTerminate(); } } while (false) |
41 | # endif |
42 | #endif |
43 | |
44 | QT_END_NAMESPACE |
45 | |
46 | #endif // QEXCEPTIONHANDLING_H |
47 | |