Intel(R) Threading Building Blocks Doxygen Documentation version 4.2.3
Loading...
Searching...
No Matches
tbb_exception.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2005-2020 Intel Corporation
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15*/
16
17#ifndef __TBB_exception_H
18#define __TBB_exception_H
19
20#define __TBB_tbb_exception_H_include_area
22
23#include "tbb_stddef.h"
24#include <exception>
25#include <new> // required for bad_alloc definition, operators new
26#include <string> // required to construct std exception classes
27
28namespace tbb {
29
31class bad_last_alloc : public std::bad_alloc {
32public:
33 const char* what() const throw() __TBB_override;
34#if __TBB_DEFAULT_DTOR_THROW_SPEC_BROKEN
36#endif
37};
38
40class __TBB_DEPRECATED improper_lock : public std::exception {
41public:
42 const char* what() const throw() __TBB_override;
43};
44
46class user_abort : public std::exception {
47public:
48 const char* what() const throw() __TBB_override;
49};
50
52class missing_wait : public std::exception {
53public:
54 const char* what() const throw() __TBB_override;
55};
56
58class invalid_multiple_scheduling : public std::exception {
59public:
60 const char* what() const throw() __TBB_override;
61};
62
63namespace internal {
66
81 eid_reserved, // free slot for backward compatibility, can be reused.
87#if __TBB_SUPPORTS_WORKERS_WAITING_IN_TERMINATE
88 // This id is used only from inside the library and only for support of CPF functionality.
89 // So, if we drop the functionality, eid_reserved1 can be safely renamed and reused.
90 eid_blocking_thread_join_impossible = eid_reserved1,
91#endif
94
97};
98
100
103
106
107} // namespace internal
108} // namespace tbb
109
110#if __TBB_TASK_GROUP_CONTEXT
111#include "tbb_allocator.h"
112#include <typeinfo> //for typeid
113
114namespace tbb {
115
117
137class __TBB_DEPRECATED tbb_exception : public std::exception
138{
142 void* operator new ( size_t );
143
144public:
145#if __clang__
146 // At -O3 or even -O2 optimization level, Clang may fully throw away an empty destructor
147 // of tbb_exception from destructors of derived classes. As a result, it does not create
148 // vtable for tbb_exception, which is a required part of TBB binary interface.
149 // Making the destructor non-empty (with just a semicolon) prevents that optimization.
150 ~tbb_exception() throw() { /* keep the semicolon! */ ; }
151#endif
152
154
155 virtual tbb_exception* move() throw() = 0;
156
158
160 virtual void destroy() throw() = 0;
161
163
167 virtual void throw_self() = 0;
168
170 virtual const char* name() const throw() = 0;
171
173 virtual const char* what() const throw() __TBB_override = 0;
174
181 void operator delete ( void* p ) {
182 internal::deallocate_via_handler_v3(p);
183 }
184};
185
187
192{
193public:
195 : tbb_exception(src), my_dynamic(false)
196 {
198 }
199
200 captured_exception( const char* name_, const char* info )
201 : my_dynamic(false)
202 {
203 set(name_, info);
204 }
205
207
208 captured_exception& operator= ( const captured_exception& src ) {
209 if ( this != &src ) {
210 clear();
211 set(src.my_exception_name, src.my_exception_info);
212 }
213 return *this;
214 }
215
217
218 void __TBB_EXPORTED_METHOD destroy() throw() __TBB_override;
219
220 void throw_self() __TBB_override { __TBB_THROW(*this); }
221
222 const char* __TBB_EXPORTED_METHOD name() const throw() __TBB_override;
223
224 const char* __TBB_EXPORTED_METHOD what() const throw() __TBB_override;
225
226 void __TBB_EXPORTED_METHOD set( const char* name, const char* info ) throw();
227 void __TBB_EXPORTED_METHOD clear() throw();
228
229private:
231 captured_exception() : my_dynamic(), my_exception_name(), my_exception_info() {}
232
234 static captured_exception* allocate( const char* name, const char* info );
235
237 const char* my_exception_name;
238 const char* my_exception_info;
239};
240
242
246template<typename ExceptionData>
248{
250
251public:
252 movable_exception( const ExceptionData& data_ )
253 : my_exception_data(data_)
254 , my_dynamic(false)
255 , my_exception_name(
257 typeid(self_type).name()
258#else /* !TBB_USE_EXCEPTIONS */
259 "movable_exception"
260#endif /* !TBB_USE_EXCEPTIONS */
261 )
262 {}
263
265 : tbb_exception(src)
266 , my_exception_data(src.my_exception_data)
267 , my_dynamic(false)
268 , my_exception_name(src.my_exception_name)
269 {}
270
272
273 const movable_exception& operator= ( const movable_exception& src ) {
274 if ( this != &src ) {
275 my_exception_data = src.my_exception_data;
276 my_exception_name = src.my_exception_name;
277 }
278 return *this;
279 }
280
281 ExceptionData& data() throw() { return my_exception_data; }
282
283 const ExceptionData& data() const throw() { return my_exception_data; }
284
285 const char* name() const throw() __TBB_override { return my_exception_name; }
286
287 const char* what() const throw() __TBB_override { return "tbb::movable_exception"; }
288
290 void* e = internal::allocate_via_handler_v3(sizeof(movable_exception));
291 if ( e ) {
292 ::new (e) movable_exception(*this);
293 ((movable_exception*)e)->my_dynamic = true;
294 }
295 return (movable_exception*)e;
296 }
297 void destroy() throw() __TBB_override {
298 __TBB_ASSERT ( my_dynamic, "Method destroy can be called only on dynamically allocated movable_exceptions" );
299 if ( my_dynamic ) {
300 this->~movable_exception();
301 internal::deallocate_via_handler_v3(this);
302 }
303 }
305
306protected:
308 ExceptionData my_exception_data;
309
310private:
313
315
316 const char* my_exception_name;
317};
318
319#if !TBB_USE_CAPTURED_EXCEPTION
320namespace internal {
321
323
326 std::exception_ptr my_ptr;
327
328public:
333
335
336 void destroy() throw();
337
339 void throw_self() { std::rethrow_exception(my_ptr); }
340
341private:
342 tbb_exception_ptr( const std::exception_ptr& src ) : my_ptr(src) {}
345 my_ptr(std::make_exception_ptr(src)) // the final function name in C++11
346 #else
347 my_ptr(std::copy_exception(src)) // early C++0x drafts name
348 #endif
349 {}
350}; // class tbb::internal::tbb_exception_ptr
351
352} // namespace internal
353#endif /* !TBB_USE_CAPTURED_EXCEPTION */
354
355} // namespace tbb
356
357#endif /* __TBB_TASK_GROUP_CONTEXT */
358
360#undef __TBB_tbb_exception_H_include_area
361
362#endif /* __TBB_exception_H */
#define __TBB_EXPORTED_FUNC
#define TBB_USE_EXCEPTIONS
Definition tbb_config.h:463
#define __TBB_MAKE_EXCEPTION_PTR_PRESENT
Definition tbb_config.h:337
#define __TBB_DEPRECATED_IN_VERBOSE_MODE
Definition tbb_config.h:647
#define __TBB_DEPRECATED
Definition tbb_config.h:636
#define __TBB_THROW(e)
Definition tbb_stddef.h:285
#define __TBB_EXPORTED_METHOD
Definition tbb_stddef.h:98
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition tbb_stddef.h:165
#define __TBB_override
Definition tbb_stddef.h:240
#define private
void const char const char int ITT_FORMAT __itt_group_sync x void const char * name
void const char const char int ITT_FORMAT __itt_group_sync p
STL namespace.
The graph class.
void __TBB_EXPORTED_FUNC throw_bad_last_alloc_exception_v4()
Obsolete.
Definition tbb_misc.cpp:122
void throw_exception(exception_id eid)
Versionless convenience wrapper for throw_exception_v4()
@ eid_reservation_length_error
@ eid_max
The last enumerator tracks the number of defined IDs. It must remain the last one.
@ eid_invalid_multiple_scheduling
@ eid_operation_not_permitted
void __TBB_EXPORTED_FUNC throw_exception_v4(exception_id)
Gathers all throw operators in one place.
Definition tbb_misc.cpp:126
Exception for concurrent containers.
const char * what() const __TBB_override
Definition tbb_misc.cpp:51
Exception for PPL locks.
Exception for user-initiated abort.
const char * what() const __TBB_override
Definition tbb_misc.cpp:53
Exception for missing wait on structured_task_group.
const char * what() const __TBB_override
Definition tbb_misc.cpp:55
Exception for repeated scheduling of the same task_handle.
const char * what() const __TBB_override
Definition tbb_misc.cpp:54
Interface to be implemented by all exceptions TBB recognizes and propagates across the threads.
virtual tbb_exception * move()=0
Creates and returns pointer to the deep copy of this exception object.
This class is used by TBB to propagate information about unhandled exceptions into the root thread.
const char * my_exception_name
__TBB_EXPORTED_METHOD ~captured_exception()
const char *__TBB_EXPORTED_METHOD name() const __TBB_override
Returns RTTI name of the originally intercepted exception.
captured_exception(const captured_exception &src)
captured_exception *__TBB_EXPORTED_METHOD move() __TBB_override
Creates and returns pointer to the deep copy of this exception object.
captured_exception(const char *name_, const char *info)
static captured_exception * allocate(const char *name, const char *info)
Functionally equivalent to {captured_exception e(name,info); return e.move();}.
const char * my_exception_info
Template that can be used to implement exception that transfers arbitrary ExceptionData to the root t...
const char * what() const __TBB_override
Returns the result of originally intercepted exception's what() method.
void throw_self() __TBB_override
Throws this exception object.
const ExceptionData & data() const
bool my_dynamic
Flag specifying whether this object has been dynamically allocated (by the move method)
const char * name() const __TBB_override
Returns RTTI name of the originally intercepted exception.
movable_exception(const ExceptionData &data_)
movable_exception(const movable_exception &src)
movable_exception * move() __TBB_override
Creates and returns pointer to the deep copy of this exception object.
ExceptionData & data()
void destroy() __TBB_override
Destroys objects created by the move() method.
const char * my_exception_name
RTTI name of this class.
movable_exception< ExceptionData > self_type
ExceptionData my_exception_data
User data.
Exception container that preserves the exact copy of the original exception.
void throw_self()
Throws the contained exception .
void destroy()
Destroys this objects.
static tbb_exception_ptr * allocate(const tbb_exception &tag)
tbb_exception_ptr(const captured_exception &src)
tbb_exception_ptr(const std::exception_ptr &src)
static tbb_exception_ptr * allocate(captured_exception &src)
This overload uses move semantics (i.e. it empties src)
static tbb_exception_ptr * allocate()

Copyright © 2005-2020 Intel Corporation. All Rights Reserved.

Intel, Pentium, Intel Xeon, Itanium, Intel XScale and VTune are registered trademarks or trademarks of Intel Corporation or its subsidiaries in the United States and other countries.

* Other names and brands may be claimed as the property of others.