Line | Source Code | Coverage |
---|
1 | /**************************************************************************** | - |
2 | ** | - |
3 | ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). | - |
4 | ** Contact: http://www.qt-project.org/legal | - |
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 Digia. For licensing terms and | - |
14 | ** conditions see http://qt.digia.com/licensing. For further information | - |
15 | ** use the contact form at http://qt.digia.com/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 as published by the Free Software | - |
20 | ** Foundation and appearing in the file LICENSE.LGPL included in the | - |
21 | ** packaging of this file. Please review the following information to | - |
22 | ** ensure the GNU Lesser General Public License version 2.1 requirements | - |
23 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - |
24 | ** | - |
25 | ** In addition, as a special exception, Digia gives you certain additional | - |
26 | ** rights. These rights are described in the Digia Qt LGPL Exception | - |
27 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - |
28 | ** | - |
29 | ** GNU General Public License Usage | - |
30 | ** Alternatively, this file may be used under the terms of the GNU | - |
31 | ** General Public License version 3.0 as published by the Free Software | - |
32 | ** Foundation and appearing in the file LICENSE.GPL included in the | - |
33 | ** packaging of this file. Please review the following information to | - |
34 | ** ensure the GNU General Public License version 3.0 requirements will be | - |
35 | ** met: http://www.gnu.org/copyleft/gpl.html. | - |
36 | ** | - |
37 | ** | - |
38 | ** $QT_END_LICENSE$ | - |
39 | ** | - |
40 | ****************************************************************************/ | - |
41 | | - |
42 | #include "qexception.h" | - |
43 | #include "QtCore/qshareddata.h" | - |
44 | | - |
45 | #ifndef QT_NO_QFUTURE | - |
46 | #ifndef QT_NO_EXCEPTIONS | - |
47 | | - |
48 | QT_BEGIN_NAMESPACE | - |
49 | | - |
50 | /*! | - |
51 | \class QException | - |
52 | \inmodule QtCore | - |
53 | \brief The QException class provides a base class for exceptions that can transferred across threads. | - |
54 | \since 5.0 | - |
55 | | - |
56 | Qt Concurrent supports throwing and catching exceptions across thread | - |
57 | boundaries, provided that the exception inherit from QException | - |
58 | and implement two helper functions: | - |
59 | | - |
60 | \snippet code/src_corelib_thread_qexception.cpp 0 | - |
61 | | - |
62 | QException subclasses must be thrown by value and | - |
63 | caught by reference: | - |
64 | | - |
65 | \snippet code/src_corelib_thread_qexception.cpp 1 | - |
66 | | - |
67 | If you throw an exception that is not a subclass of QException, | - |
68 | the Qt functions will throw a QUnhandledException | - |
69 | in the receiver thread. | - |
70 | | - |
71 | When using QFuture, transferred exceptions will be thrown when calling the following functions: | - |
72 | \list | - |
73 | \li QFuture::waitForFinished() | - |
74 | \li QFuture::result() | - |
75 | \li QFuture::resultAt() | - |
76 | \li QFuture::results() | - |
77 | \endlist | - |
78 | */ | - |
79 | | - |
80 | /*! | - |
81 | \fn QException::raise() const | - |
82 | In your QException subclass, reimplement raise() like this: | - |
83 | | - |
84 | \snippet code/src_corelib_thread_qexception.cpp 2 | - |
85 | */ | - |
86 | | - |
87 | /*! | - |
88 | \fn QException::clone() const | - |
89 | In your QException subclass, reimplement clone() like this: | - |
90 | | - |
91 | \snippet code/src_corelib_thread_qexception.cpp 3 | - |
92 | */ | - |
93 | | - |
94 | /*! | - |
95 | \class QUnhandledException | - |
96 | \inmodule QtCore | - |
97 | | - |
98 | \brief The UnhandledException class represents an unhandled exception in a worker thread. | - |
99 | \since 5.0 | - |
100 | | - |
101 | If a worker thread throws an exception that is not a subclass of QException, | - |
102 | the Qt functions will throw a QUnhandledException | - |
103 | on the receiver thread side. | - |
104 | | - |
105 | Inheriting from this class is not supported. | - |
106 | */ | - |
107 | | - |
108 | /*! | - |
109 | \fn QUnhandledException::raise() const | - |
110 | \internal | - |
111 | */ | - |
112 | | - |
113 | /*! | - |
114 | \fn QUnhandledException::clone() const | - |
115 | \internal | - |
116 | */ | - |
117 | | - |
118 | void QException::raise() const | - |
119 | { | - |
120 | QException e = *this; executed (the execution status of this line is deduced): QException e = *this; | - |
121 | throw e; executed: throw e; Execution Count:12 | 12 |
122 | } | - |
123 | | - |
124 | QException *QException::clone() const | - |
125 | { | - |
126 | return new QException(*this); executed: return new QException(*this); Execution Count:12 | 12 |
127 | } | - |
128 | | - |
129 | void QUnhandledException::raise() const | - |
130 | { | - |
131 | QUnhandledException e = *this; executed (the execution status of this line is deduced): QUnhandledException e = *this; | - |
132 | throw e; executed: throw e; Execution Count:3 | 3 |
133 | } | - |
134 | | - |
135 | QUnhandledException *QUnhandledException::clone() const | - |
136 | { | - |
137 | return new QUnhandledException(*this); executed: return new QUnhandledException(*this); Execution Count:4 | 4 |
138 | } | - |
139 | | - |
140 | #ifndef Q_QDOC | - |
141 | | - |
142 | namespace QtPrivate { | - |
143 | | - |
144 | class Base : public QSharedData | - |
145 | { | - |
146 | public: | - |
147 | Base(QException *exception) | - |
148 | : exception(exception), hasThrown(false) { } executed: } Execution Count:666411 | 666411 |
149 | ~Base() { delete exception; } executed: } Execution Count:667145 | 667145 |
150 | | - |
151 | QException *exception; | - |
152 | bool hasThrown; | - |
153 | }; | - |
154 | | - |
155 | ExceptionHolder::ExceptionHolder(QException *exception) | - |
156 | : base(new Base(exception)) {} executed: } Execution Count:667660 | 667660 |
157 | | - |
158 | ExceptionHolder::ExceptionHolder(const ExceptionHolder &other) | - |
159 | : base(other.base) | - |
160 | {} | 0 |
161 | | - |
162 | void ExceptionHolder::operator=(const ExceptionHolder &other) | - |
163 | { | - |
164 | base = other.base; executed (the execution status of this line is deduced): base = other.base; | - |
165 | } executed: } Execution Count:18 | 18 |
166 | | - |
167 | ExceptionHolder::~ExceptionHolder() | - |
168 | {} | - |
169 | | - |
170 | QException *ExceptionHolder::exception() const | - |
171 | { | - |
172 | return base->exception; executed: return base->exception; Execution Count:607398 | 607398 |
173 | } | - |
174 | | - |
175 | void ExceptionStore::setException(const QException &e) | - |
176 | { | - |
177 | if (hasException() == false) evaluated: hasException() == false yes Evaluation Count:18 | yes Evaluation Count:31 |
| 18-31 |
178 | exceptionHolder = ExceptionHolder(e.clone()); executed: exceptionHolder = ExceptionHolder(e.clone()); Execution Count:18 | 18 |
179 | } executed: } Execution Count:49 | 49 |
180 | | - |
181 | bool ExceptionStore::hasException() const | - |
182 | { | - |
183 | return (exceptionHolder.exception() != 0); executed: return (exceptionHolder.exception() != 0); Execution Count:606942 | 606942 |
184 | } | - |
185 | | - |
186 | ExceptionHolder ExceptionStore::exception() | - |
187 | { | - |
188 | return exceptionHolder; never executed: return exceptionHolder; | 0 |
189 | } | - |
190 | | - |
191 | void ExceptionStore::throwPossibleException() | - |
192 | { | - |
193 | if (hasException() ) { evaluated: hasException() yes Evaluation Count:17 | yes Evaluation Count:607120 |
| 17-607120 |
194 | exceptionHolder.base->hasThrown = true; never executed (the execution status of this line is deduced): exceptionHolder.base->hasThrown = true; | - |
195 | exceptionHolder.exception()->raise(); never executed (the execution status of this line is deduced): exceptionHolder.exception()->raise(); | - |
196 | } | 0 |
197 | } executed: } Execution Count:606754 | 606754 |
198 | | - |
199 | bool ExceptionStore::hasThrown() const { return exceptionHolder.base->hasThrown; } never executed: return exceptionHolder.base->hasThrown; | 0 |
200 | | - |
201 | } // namespace QtPrivate | - |
202 | | - |
203 | #endif //Q_QDOC | - |
204 | | - |
205 | QT_END_NAMESPACE | - |
206 | | - |
207 | #endif // QT_NO_EXCEPTIONS | - |
208 | #endif // QT_NO_QFUTURE | - |
209 | | - |
| | |