| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/thread/qexception.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||
| 2 | ** | - | ||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||
| 5 | ** | - | ||||||
| 6 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||
| 7 | ** | - | ||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||
| 9 | ** Commercial License Usage | - | ||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||
| 15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||
| 16 | ** | - | ||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||
| 19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||
| 25 | ** | - | ||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||
| 29 | ** | - | ||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||
| 31 | ** | - | ||||||
| 32 | ****************************************************************************/ | - | ||||||
| 33 | - | |||||||
| 34 | #include "qexception.h" | - | ||||||
| 35 | #include "QtCore/qshareddata.h" | - | ||||||
| 36 | - | |||||||
| 37 | #ifndef QT_NO_QFUTURE | - | ||||||
| 38 | #ifndef QT_NO_EXCEPTIONS | - | ||||||
| 39 | - | |||||||
| 40 | QT_BEGIN_NAMESPACE | - | ||||||
| 41 | - | |||||||
| 42 | /*! | - | ||||||
| 43 | \class QException | - | ||||||
| 44 | \inmodule QtCore | - | ||||||
| 45 | \brief The QException class provides a base class for exceptions that can transferred across threads. | - | ||||||
| 46 | \since 5.0 | - | ||||||
| 47 | - | |||||||
| 48 | Qt Concurrent supports throwing and catching exceptions across thread | - | ||||||
| 49 | boundaries, provided that the exception inherit from QException | - | ||||||
| 50 | and implement two helper functions: | - | ||||||
| 51 | - | |||||||
| 52 | \snippet code/src_corelib_thread_qexception.cpp 0 | - | ||||||
| 53 | - | |||||||
| 54 | QException subclasses must be thrown by value and | - | ||||||
| 55 | caught by reference: | - | ||||||
| 56 | - | |||||||
| 57 | \snippet code/src_corelib_thread_qexception.cpp 1 | - | ||||||
| 58 | - | |||||||
| 59 | If you throw an exception that is not a subclass of QException, | - | ||||||
| 60 | the Qt functions will throw a QUnhandledException | - | ||||||
| 61 | in the receiver thread. | - | ||||||
| 62 | - | |||||||
| 63 | When using QFuture, transferred exceptions will be thrown when calling the following functions: | - | ||||||
| 64 | \list | - | ||||||
| 65 | \li QFuture::waitForFinished() | - | ||||||
| 66 | \li QFuture::result() | - | ||||||
| 67 | \li QFuture::resultAt() | - | ||||||
| 68 | \li QFuture::results() | - | ||||||
| 69 | \endlist | - | ||||||
| 70 | */ | - | ||||||
| 71 | - | |||||||
| 72 | /*! | - | ||||||
| 73 | \fn QException::raise() const | - | ||||||
| 74 | In your QException subclass, reimplement raise() like this: | - | ||||||
| 75 | - | |||||||
| 76 | \snippet code/src_corelib_thread_qexception.cpp 2 | - | ||||||
| 77 | */ | - | ||||||
| 78 | - | |||||||
| 79 | /*! | - | ||||||
| 80 | \fn QException::clone() const | - | ||||||
| 81 | In your QException subclass, reimplement clone() like this: | - | ||||||
| 82 | - | |||||||
| 83 | \snippet code/src_corelib_thread_qexception.cpp 3 | - | ||||||
| 84 | */ | - | ||||||
| 85 | - | |||||||
| 86 | /*! | - | ||||||
| 87 | \class QUnhandledException | - | ||||||
| 88 | \inmodule QtCore | - | ||||||
| 89 | - | |||||||
| 90 | \brief The UnhandledException class represents an unhandled exception in a worker thread. | - | ||||||
| 91 | \since 5.0 | - | ||||||
| 92 | - | |||||||
| 93 | If a worker thread throws an exception that is not a subclass of QException, | - | ||||||
| 94 | the Qt functions will throw a QUnhandledException | - | ||||||
| 95 | on the receiver thread side. | - | ||||||
| 96 | - | |||||||
| 97 | Inheriting from this class is not supported. | - | ||||||
| 98 | */ | - | ||||||
| 99 | - | |||||||
| 100 | /*! | - | ||||||
| 101 | \fn QUnhandledException::raise() const | - | ||||||
| 102 | \internal | - | ||||||
| 103 | */ | - | ||||||
| 104 | - | |||||||
| 105 | /*! | - | ||||||
| 106 | \fn QUnhandledException::clone() const | - | ||||||
| 107 | \internal | - | ||||||
| 108 | */ | - | ||||||
| 109 | - | |||||||
| 110 | QException::~QException() | - | ||||||
| 111 | #ifdef Q_COMPILER_NOEXCEPT | - | ||||||
| 112 | noexcept | - | ||||||
| 113 | #else | - | ||||||
| 114 | throw() | - | ||||||
| 115 | #endif | - | ||||||
| 116 | { | - | ||||||
| 117 | // must stay empty until ### Qt 6 | - | ||||||
| 118 | } | - | ||||||
| 119 | - | |||||||
| 120 | void QException::raise() const | - | ||||||
| 121 | { | - | ||||||
| 122 | QException e = *this; | - | ||||||
| 123 | throw e; executed 16 times by 4 tests: throw e;Executed by:
| 16 | ||||||
| 124 | } | - | ||||||
| 125 | - | |||||||
| 126 | QException *QException::clone() const | - | ||||||
| 127 | { | - | ||||||
| 128 | return new QException(*this); executed 16 times by 4 tests: return new QException(*this);Executed by:
| 16 | ||||||
| 129 | } | - | ||||||
| 130 | - | |||||||
| 131 | QUnhandledException::~QUnhandledException() | - | ||||||
| 132 | #ifdef Q_COMPILER_NOEXCEPT | - | ||||||
| 133 | noexcept | - | ||||||
| 134 | #else | - | ||||||
| 135 | throw() | - | ||||||
| 136 | #endif | - | ||||||
| 137 | { | - | ||||||
| 138 | // must stay empty until ### Qt 6 | - | ||||||
| 139 | } | - | ||||||
| 140 | - | |||||||
| 141 | void QUnhandledException::raise() const | - | ||||||
| 142 | { | - | ||||||
| 143 | QUnhandledException e = *this; | - | ||||||
| 144 | throw e; executed 3 times by 1 test: throw e;Executed by:
| 3 | ||||||
| 145 | } | - | ||||||
| 146 | - | |||||||
| 147 | QUnhandledException *QUnhandledException::clone() const | - | ||||||
| 148 | { | - | ||||||
| 149 | return new QUnhandledException(*this); executed 3 times by 1 test: return new QUnhandledException(*this);Executed by:
| 3 | ||||||
| 150 | } | - | ||||||
| 151 | - | |||||||
| 152 | #ifndef Q_QDOC | - | ||||||
| 153 | - | |||||||
| 154 | namespace QtPrivate { | - | ||||||
| 155 | - | |||||||
| 156 | class Base : public QSharedData | - | ||||||
| 157 | { | - | ||||||
| 158 | public: | - | ||||||
| 159 | Base(QException *exception) | - | ||||||
| 160 | : exception(exception), hasThrown(false) { } executed 21 times by 4 tests: end of blockExecuted by:
| 21 | ||||||
| 161 | ~Base() { delete exception; } executed 21 times by 4 tests: end of blockExecuted by:
| 21 | ||||||
| 162 | - | |||||||
| 163 | QException *exception; | - | ||||||
| 164 | bool hasThrown; | - | ||||||
| 165 | }; | - | ||||||
| 166 | - | |||||||
| 167 | ExceptionHolder::ExceptionHolder(QException *exception) | - | ||||||
| 168 | : executed 209757 times by 12 tests: base(exception ? new Base(exception) : Q_NULLPTR) {}end of blockExecuted by:
executed 209757 times by 12 tests: end of blockExecuted by:
| 209757 | ||||||
| 169 | - | |||||||
| 170 | ExceptionHolder::ExceptionHolder(const ExceptionHolder &other) | - | ||||||
| 171 | : base(other.base) | - | ||||||
| 172 | {} never executed: end of block | 0 | ||||||
| 173 | - | |||||||
| 174 | void ExceptionHolder::operator=(const ExceptionHolder &other) | - | ||||||
| 175 | { | - | ||||||
| 176 | base = other.base; | - | ||||||
| 177 | } executed 21 times by 4 tests: end of blockExecuted by:
| 21 | ||||||
| 178 | - | |||||||
| 179 | ExceptionHolder::~ExceptionHolder() | - | ||||||
| 180 | {} | - | ||||||
| 181 | - | |||||||
| 182 | QException *ExceptionHolder::exception() const | - | ||||||
| 183 | { | - | ||||||
| 184 | if (!base)
| 46-233734 | ||||||
| 185 | return Q_NULLPTR; executed 233734 times by 12 tests: return nullptr;Executed by:
| 233734 | ||||||
| 186 | return base->exception; executed 46 times by 4 tests: return base->exception;Executed by:
| 46 | ||||||
| 187 | } | - | ||||||
| 188 | - | |||||||
| 189 | void ExceptionStore::setException(const QException &e) | - | ||||||
| 190 | { | - | ||||||
| 191 | if (hasException() == false)
| 4-21 | ||||||
| 192 | exceptionHolder = ExceptionHolder(e.clone()); executed 21 times by 4 tests: exceptionHolder = ExceptionHolder(e.clone());Executed by:
| 21 | ||||||
| 193 | } executed 25 times by 4 tests: end of blockExecuted by:
| 25 | ||||||
| 194 | - | |||||||
| 195 | bool ExceptionStore::hasException() const | - | ||||||
| 196 | { | - | ||||||
| 197 | return (exceptionHolder.exception() != 0); executed 233759 times by 12 tests: return (exceptionHolder.exception() != 0);Executed by:
| 233759 | ||||||
| 198 | } | - | ||||||
| 199 | - | |||||||
| 200 | ExceptionHolder ExceptionStore::exception() | - | ||||||
| 201 | { | - | ||||||
| 202 | return exceptionHolder; never executed: return exceptionHolder; | 0 | ||||||
| 203 | } | - | ||||||
| 204 | - | |||||||
| 205 | void ExceptionStore::throwPossibleException() | - | ||||||
| 206 | { | - | ||||||
| 207 | if (hasException() ) {
| 21-233713 | ||||||
| 208 | exceptionHolder.base->hasThrown = true; | - | ||||||
| 209 | exceptionHolder.exception()->raise(); | - | ||||||
| 210 | } never executed: end of block | 0 | ||||||
| 211 | } executed 233713 times by 12 tests: end of blockExecuted by:
| 233713 | ||||||
| 212 | - | |||||||
| 213 | bool ExceptionStore::hasThrown() const { return exceptionHolder.base->hasThrown; } never executed: return exceptionHolder.base->hasThrown; | 0 | ||||||
| 214 | - | |||||||
| 215 | } // namespace QtPrivate | - | ||||||
| 216 | - | |||||||
| 217 | #endif //Q_QDOC | - | ||||||
| 218 | - | |||||||
| 219 | QT_END_NAMESPACE | - | ||||||
| 220 | - | |||||||
| 221 | #endif // QT_NO_EXCEPTIONS | - | ||||||
| 222 | #endif // QT_NO_QFUTURE | - | ||||||
| Source code | Switch to Preprocessed file |