Intel(R) Threading Building Blocks Doxygen Documentation  version 4.2.3
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 
28 namespace tbb {
29 
31 class bad_last_alloc : public std::bad_alloc {
32 public:
33  const char* what() const throw() __TBB_override;
34 #if __TBB_DEFAULT_DTOR_THROW_SPEC_BROKEN
35  ~bad_last_alloc() throw() __TBB_override {}
36 #endif
37 };
38 
40 class __TBB_DEPRECATED improper_lock : public std::exception {
41 public:
42  const char* what() const throw() __TBB_override;
43 };
44 
46 class user_abort : public std::exception {
47 public:
48  const char* what() const throw() __TBB_override;
49 };
50 
52 class missing_wait : public std::exception {
53 public:
54  const char* what() const throw() __TBB_override;
55 };
56 
58 class invalid_multiple_scheduling : public std::exception {
59 public:
60  const char* what() const throw() __TBB_override;
61 };
62 
63 namespace 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 
105 inline void throw_exception ( exception_id eid ) { throw_exception_v4(eid); }
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 
114 namespace tbb {
115 
117 
137 class __TBB_DEPRECATED tbb_exception : public std::exception
138 {
142  void* operator new ( size_t );
143 
144 public:
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 ) {
183  }
184 };
185 
187 
192 {
193 public:
195  : tbb_exception(src), my_dynamic(false)
196  {
197  set(src.my_exception_name, src.my_exception_info);
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 
229 private:
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 
246 template<typename ExceptionData>
248 {
250 
251 public:
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 
264  movable_exception( const movable_exception& src ) throw ()
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 
271  ~movable_exception() throw() {}
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 
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();
302  }
303  }
304  void throw_self() __TBB_override { __TBB_THROW( *this ); }
305 
306 protected:
308  ExceptionData my_exception_data;
309 
310 private:
313 
315 
316  const char* my_exception_name;
317 };
318 
319 #if !TBB_USE_CAPTURED_EXCEPTION
320 namespace internal {
321 
323 
326  std::exception_ptr my_ptr;
327 
328 public:
329  static tbb_exception_ptr* allocate();
330  static tbb_exception_ptr* allocate( const tbb_exception& tag );
333 
335 
336  void destroy() throw();
337 
339  void throw_self() { std::rethrow_exception(my_ptr); }
340 
341 private:
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 */
tbb::bad_last_alloc
Exception for concurrent containers.
Definition: tbb_exception.h:31
__TBB_DEPRECATED
#define __TBB_DEPRECATED
Definition: tbb_config.h:636
tbb::internal::eid_improper_lock
@ eid_improper_lock
Definition: tbb_exception.h:76
tbb::internal::deallocate_via_handler_v3
void __TBB_EXPORTED_FUNC deallocate_via_handler_v3(void *p)
Deallocates memory using FreeHandler.
Definition: cache_aligned_allocator.cpp:232
tbb::movable_exception::destroy
void destroy() __TBB_override
Destroys objects created by the move() method.
Definition: tbb_exception.h:297
tbb::invalid_multiple_scheduling
Exception for repeated scheduling of the same task_handle.
Definition: tbb_exception.h:58
internal
Definition: _flow_graph_async_msg_impl.h:24
tbb::internal::eid_index_range_error
@ eid_index_range_error
Definition: tbb_exception.h:73
tbb::internal::eid_condvar_wait_failed
@ eid_condvar_wait_failed
Definition: tbb_exception.h:79
tbb::internal::eid_nonpositive_step
@ eid_nonpositive_step
Definition: tbb_exception.h:70
__TBB_ASSERT
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:165
tbb::user_abort
Exception for user-initiated abort.
Definition: tbb_exception.h:46
tbb::internal::eid_operation_not_permitted
@ eid_operation_not_permitted
Definition: tbb_exception.h:78
tbb::captured_exception::captured_exception
captured_exception(const captured_exception &src)
Definition: tbb_exception.h:194
tbb::internal::tbb_exception_ptr::destroy
void destroy()
Destroys this objects.
tbb::internal::throw_exception
void throw_exception(exception_id eid)
Versionless convenience wrapper for throw_exception_v4()
Definition: tbb_exception.h:105
tbb::internal::eid_segment_range_error
@ eid_segment_range_error
Definition: tbb_exception.h:72
__TBB_MAKE_EXCEPTION_PTR_PRESENT
#define __TBB_MAKE_EXCEPTION_PTR_PRESENT
Definition: tbb_config.h:337
tbb::internal::tbb_exception_ptr::my_ptr
std::exception_ptr my_ptr
Definition: tbb_exception.h:326
tbb::movable_exception::my_exception_data
ExceptionData my_exception_data
User data.
Definition: tbb_exception.h:308
__TBB_THROW
#define __TBB_THROW(e)
Definition: tbb_stddef.h:285
tbb::internal::eid_possible_deadlock
@ eid_possible_deadlock
Definition: tbb_exception.h:77
tbb
The graph class.
Definition: serial/tbb/parallel_for.h:46
tbb::movable_exception::throw_self
void throw_self() __TBB_override
Throws this exception object.
Definition: tbb_exception.h:304
tbb::internal::throw_exception_v4
void __TBB_EXPORTED_FUNC throw_exception_v4(exception_id)
Gathers all throw operators in one place.
Definition: tbb_misc.cpp:126
tbb::internal::tbb_exception_ptr
Exception container that preserves the exact copy of the original exception.
Definition: tbb_exception.h:325
tbb::captured_exception::my_dynamic
bool my_dynamic
Definition: tbb_exception.h:236
tbb::movable_exception::data
const ExceptionData & data() const
Definition: tbb_exception.h:283
tbb::internal::eid_out_of_range
@ eid_out_of_range
Definition: tbb_exception.h:71
tbb::bad_last_alloc::what
const char * what() const __TBB_override
Definition: tbb_misc.cpp:51
tbb::movable_exception::my_exception_name
const char * my_exception_name
RTTI name of this class.
Definition: tbb_exception.h:316
tbb::internal::throw_bad_last_alloc_exception_v4
void __TBB_EXPORTED_FUNC throw_bad_last_alloc_exception_v4()
Obsolete.
Definition: tbb_misc.cpp:122
tbb::captured_exception
This class is used by TBB to propagate information about unhandled exceptions into the root thread.
Definition: tbb_exception.h:191
tbb::movable_exception::self_type
movable_exception< ExceptionData > self_type
Definition: tbb_exception.h:249
private
#define private
Definition: scheduler_common.h:35
TBB_USE_EXCEPTIONS
#define TBB_USE_EXCEPTIONS
Definition: tbb_config.h:463
tbb::internal::exception_id
exception_id
Definition: tbb_exception.h:67
tbb::internal::eid_invalid_key
@ eid_invalid_key
Definition: tbb_exception.h:84
tbb::internal::eid_invalid_swap
@ eid_invalid_swap
Definition: tbb_exception.h:82
tbb::user_abort::what
const char * what() const __TBB_override
Definition: tbb_misc.cpp:53
tbb::movable_exception::data
ExceptionData & data()
Definition: tbb_exception.h:281
tbb::internal::eid_bad_last_alloc
@ eid_bad_last_alloc
Definition: tbb_exception.h:69
tbb::captured_exception::captured_exception
captured_exception(const char *name_, const char *info)
Definition: tbb_exception.h:200
tbb::movable_exception::my_dynamic
bool my_dynamic
Flag specifying whether this object has been dynamically allocated (by the move method)
Definition: tbb_exception.h:312
tbb::internal::eid_bad_tagged_msg_cast
@ eid_bad_tagged_msg_cast
Definition: tbb_exception.h:92
tbb::movable_exception::~movable_exception
~movable_exception()
Definition: tbb_exception.h:271
tbb::internal::eid_reserved
@ eid_reserved
Definition: tbb_exception.h:81
tbb::movable_exception::movable_exception
movable_exception(const movable_exception &src)
Definition: tbb_exception.h:264
tbb::move
void move(tbb_thread &t1, tbb_thread &t2)
Definition: tbb_thread.h:319
tbb::movable_exception::what
const char * what() const __TBB_override
Returns the result of originally intercepted exception's what() method.
Definition: tbb_exception.h:287
tbb::movable_exception::movable_exception
movable_exception(const ExceptionData &data_)
Definition: tbb_exception.h:252
tbb::captured_exception::my_exception_info
const char * my_exception_info
Definition: tbb_exception.h:238
tbb::invalid_multiple_scheduling::what
const char * what() const __TBB_override
Definition: tbb_misc.cpp:54
tbb::missing_wait
Exception for missing wait on structured_task_group.
Definition: tbb_exception.h:52
_warning_suppress_disable_notice.h
__TBB_override
#define __TBB_override
Definition: tbb_stddef.h:240
tbb::captured_exception::my_exception_name
const char * my_exception_name
Definition: tbb_exception.h:237
tbb::internal::allocate_via_handler_v3
void *__TBB_EXPORTED_FUNC allocate_via_handler_v3(size_t n)
Allocates memory using MallocHandler.
Definition: cache_aligned_allocator.cpp:224
__TBB_EXPORTED_FUNC
#define __TBB_EXPORTED_FUNC
Definition: scalable_allocator.h:38
tbb::internal::eid_reserved1
@ eid_reserved1
Definition: tbb_exception.h:86
tbb::improper_lock
Exception for PPL locks.
Definition: tbb_exception.h:40
tbb::internal::eid_bad_alloc
@ eid_bad_alloc
Definition: tbb_exception.h:68
tbb::internal::tbb_exception_ptr::tbb_exception_ptr
tbb_exception_ptr(const captured_exception &src)
Definition: tbb_exception.h:343
tbb::movable_exception
Template that can be used to implement exception that transfers arbitrary ExceptionData to the root t...
Definition: tbb_exception.h:247
tbb::internal::eid_max
@ eid_max
The last enumerator tracks the number of defined IDs. It must remain the last one.
Definition: tbb_exception.h:96
tbb::internal::eid_user_abort
@ eid_user_abort
Definition: tbb_exception.h:85
tbb::internal::eid_invalid_multiple_scheduling
@ eid_invalid_multiple_scheduling
Definition: tbb_exception.h:75
tbb::internal::eid_reservation_length_error
@ eid_reservation_length_error
Definition: tbb_exception.h:83
tbb::internal::tbb_exception_ptr::tbb_exception_ptr
tbb_exception_ptr(const std::exception_ptr &src)
Definition: tbb_exception.h:342
tbb::internal::eid_invalid_load_factor
@ eid_invalid_load_factor
Definition: tbb_exception.h:80
name
void const char const char int ITT_FORMAT __itt_group_sync x void const char * name
Definition: ittnotify_static.h:93
__TBB_DEPRECATED_IN_VERBOSE_MODE
#define __TBB_DEPRECATED_IN_VERBOSE_MODE
Definition: tbb_config.h:647
tbb_stddef.h
_warning_suppress_enable_notice.h
p
void const char const char int ITT_FORMAT __itt_group_sync p
Definition: ittnotify_static.h:91
tbb::movable_exception::move
movable_exception * move() __TBB_override
Creates and returns pointer to the deep copy of this exception object.
Definition: tbb_exception.h:289
__TBB_EXPORTED_METHOD
#define __TBB_EXPORTED_METHOD
Definition: tbb_stddef.h:98
tbb::internal::tbb_exception_ptr::allocate
static tbb_exception_ptr * allocate()
tbb::tbb_exception
Interface to be implemented by all exceptions TBB recognizes and propagates across the threads.
Definition: tbb_exception.h:137
tbb_allocator.h
tbb::missing_wait::what
const char * what() const __TBB_override
Definition: tbb_misc.cpp:55
tbb::movable_exception::name
const char * name() const __TBB_override
Returns RTTI name of the originally intercepted exception.
Definition: tbb_exception.h:285
tbb::internal::eid_missing_wait
@ eid_missing_wait
Definition: tbb_exception.h:74
tbb::internal::tbb_exception_ptr::throw_self
void throw_self()
Throws the contained exception .
Definition: tbb_exception.h:339

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.