qexception.cpp

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

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9