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) 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-
40QT_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-
110QException::~QException()-
111#ifdef Q_COMPILER_NOEXCEPT-
112 noexcept-
113#else-
114 throw()-
115#endif-
116{-
117 // must stay empty until ### Qt 6-
118}-
119-
120void QException::raise() const-
121{-
122 QException e = *this;-
123 throw e;
executed 16 times by 4 tests: throw e;
Executed by:
  • tst_QFuture
  • tst_QtConcurrentMap
  • tst_QtConcurrentRun
  • tst_QtConcurrentThreadEngine
16
124}-
125-
126QException *QException::clone() const-
127{-
128 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
129}-
130-
131QUnhandledException::~QUnhandledException()-
132#ifdef Q_COMPILER_NOEXCEPT-
133 noexcept-
134#else-
135 throw()-
136#endif-
137{-
138 // must stay empty until ### Qt 6-
139}-
140-
141void QUnhandledException::raise() const-
142{-
143 QUnhandledException e = *this;-
144 throw e;
executed 3 times by 1 test: throw e;
Executed by:
  • tst_QtConcurrentThreadEngine
3
145}-
146-
147QUnhandledException *QUnhandledException::clone() const-
148{-
149 return new QUnhandledException(*this);
executed 3 times by 1 test: return new QUnhandledException(*this);
Executed by:
  • tst_QtConcurrentThreadEngine
3
150}-
151-
152#ifndef Q_QDOC-
153-
154namespace QtPrivate {-
155-
156class Base : public QSharedData-
157{-
158public:-
159 Base(QException *exception)-
160 : exception(exception), hasThrown(false) { }
executed 21 times by 4 tests: end of block
Executed by:
  • tst_QFuture
  • tst_QtConcurrentMap
  • tst_QtConcurrentRun
  • tst_QtConcurrentThreadEngine
21
161 ~Base() { delete exception; }
executed 21 times by 4 tests: end of block
Executed by:
  • tst_QFuture
  • tst_QtConcurrentMap
  • tst_QtConcurrentRun
  • tst_QtConcurrentThreadEngine
21
162-
163 QException *exception;-
164 bool hasThrown;-
165};-
166-
167ExceptionHolder::ExceptionHolder(QException *exception)-
168:
executed 209757 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 209757 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
209757
169-
170ExceptionHolder::ExceptionHolder(const ExceptionHolder &other)-
171: base(other.base)-
172{}
never executed: end of block
0
173-
174void ExceptionHolder::operator=(const ExceptionHolder &other)-
175{-
176 base = other.base;-
177}
executed 21 times by 4 tests: end of block
Executed by:
  • tst_QFuture
  • tst_QtConcurrentMap
  • tst_QtConcurrentRun
  • tst_QtConcurrentThreadEngine
21
178-
179ExceptionHolder::~ExceptionHolder()-
180{}-
181-
182QException *ExceptionHolder::exception() const-
183{-
184 if (!base)
!baseDescription
TRUEevaluated 233734 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-233734
185 return Q_NULLPTR;
executed 233734 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
233734
186 return base->exception;
executed 46 times by 4 tests: return base->exception;
Executed by:
  • tst_QFuture
  • tst_QtConcurrentMap
  • tst_QtConcurrentRun
  • tst_QtConcurrentThreadEngine
46
187}-
188-
189void ExceptionStore::setException(const QException &e)-
190{-
191 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
192 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
193}
executed 25 times by 4 tests: end of block
Executed by:
  • tst_QFuture
  • tst_QtConcurrentMap
  • tst_QtConcurrentRun
  • tst_QtConcurrentThreadEngine
25
194-
195bool ExceptionStore::hasException() const-
196{-
197 return (exceptionHolder.exception() != 0);
executed 233759 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
233759
198}-
199-
200ExceptionHolder ExceptionStore::exception()-
201{-
202 return exceptionHolder;
never executed: return exceptionHolder;
0
203}-
204-
205void ExceptionStore::throwPossibleException()-
206{-
207 if (hasException() ) {
hasException()Description
TRUEevaluated 21 times by 4 tests
Evaluated by:
  • tst_QFuture
  • tst_QtConcurrentMap
  • tst_QtConcurrentRun
  • tst_QtConcurrentThreadEngine
FALSEevaluated 233713 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-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 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
233713
212-
213bool ExceptionStore::hasThrown() const { return exceptionHolder.base->hasThrown; }
never executed: return exceptionHolder.base->hasThrown;
0
214-
215} // namespace QtPrivate-
216-
217#endif //Q_QDOC-
218-
219QT_END_NAMESPACE-
220-
221#endif // QT_NO_EXCEPTIONS-
222#endif // QT_NO_QFUTURE-
Source codeSwitch to Preprocessed file

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