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-2019 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 
18 
19 */
20 
21 #ifndef __TBB_exception_H
22 #define __TBB_exception_H
23 
24 #include "tbb_stddef.h"
25 #include <exception>
26 #include <new> // required for bad_alloc definition, operators new
27 #include <string> // required to construct std exception classes
28 
29 namespace tbb {
30 
32 class bad_last_alloc : public std::bad_alloc {
33 public:
34  const char* what() const throw() __TBB_override;
35 #if __TBB_DEFAULT_DTOR_THROW_SPEC_BROKEN
36  ~bad_last_alloc() throw() __TBB_override {}
37 #endif
38 };
39 
41 class improper_lock : public std::exception {
42 public:
43  const char* what() const throw() __TBB_override;
44 };
45 
47 class user_abort : public std::exception {
48 public:
49  const char* what() const throw() __TBB_override;
50 };
51 
53 class missing_wait : public std::exception {
54 public:
55  const char* what() const throw() __TBB_override;
56 };
57 
59 class invalid_multiple_scheduling : public std::exception {
60 public:
61  const char* what() const throw() __TBB_override;
62 };
63 
64 namespace internal {
67 
82  eid_reserved, // free slot for backward compatibility, can be reused.
88 #if __TBB_SUPPORTS_WORKERS_WAITING_IN_TERMINATE
89  // This id is used only from inside the library and only for support of CPF functionality.
90  // So, if we drop the functionality, eid_reserved1 can be safely renamed and reused.
91  eid_blocking_thread_join_impossible = eid_reserved1,
92 #endif
95 
98 };
99 
101 
104 
106 inline void throw_exception ( exception_id eid ) { throw_exception_v4(eid); }
107 
108 } // namespace internal
109 } // namespace tbb
110 
111 #if __TBB_TASK_GROUP_CONTEXT
112 #include "tbb_allocator.h"
113 #include <typeinfo> //for typeid
114 
115 namespace tbb {
116 
118 
138 class tbb_exception : public std::exception
139 {
143  void* operator new ( size_t );
144 
145 public:
146 #if __clang__
147  // At -O3 or even -O2 optimization level, Clang may fully throw away an empty destructor
148  // of tbb_exception from destructors of derived classes. As a result, it does not create
149  // vtable for tbb_exception, which is a required part of TBB binary interface.
150  // Making the destructor non-empty (with just a semicolon) prevents that optimization.
151  ~tbb_exception() throw() { /* keep the semicolon! */ ; }
152 #endif
153 
155 
156  virtual tbb_exception* move() throw() = 0;
157 
159 
161  virtual void destroy() throw() = 0;
162 
164 
168  virtual void throw_self() = 0;
169 
171  virtual const char* name() const throw() = 0;
172 
174  virtual const char* what() const throw() __TBB_override = 0;
175 
182  void operator delete ( void* p ) {
184  }
185 };
186 
188 
193 {
194 public:
196  : tbb_exception(src), my_dynamic(false)
197  {
199  }
200 
201  captured_exception( const char* name_, const char* info )
202  : my_dynamic(false)
203  {
204  set(name_, info);
205  }
206 
208 
209  captured_exception& operator= ( const captured_exception& src ) {
210  if ( this != &src ) {
211  clear();
212  set(src.my_exception_name, src.my_exception_info);
213  }
214  return *this;
215  }
216 
218 
220 
222 
223  const char* __TBB_EXPORTED_METHOD name() const throw() __TBB_override;
224 
225  const char* __TBB_EXPORTED_METHOD what() const throw() __TBB_override;
226 
227  void __TBB_EXPORTED_METHOD set( const char* name, const char* info ) throw();
228  void __TBB_EXPORTED_METHOD clear() throw();
229 
230 private:
233 
235  static captured_exception* allocate( const char* name, const char* info );
236 
238  const char* my_exception_name;
239  const char* my_exception_info;
240 };
241 
243 
247 template<typename ExceptionData>
249 {
251 
252 public:
253  movable_exception( const ExceptionData& data_ )
254  : my_exception_data(data_)
255  , my_dynamic(false)
258  typeid(self_type).name()
259 #else /* !TBB_USE_EXCEPTIONS */
260  "movable_exception"
261 #endif /* !TBB_USE_EXCEPTIONS */
262  )
263  {}
264 
265  movable_exception( const movable_exception& src ) throw ()
266  : tbb_exception(src)
267  , my_exception_data(src.my_exception_data)
268  , my_dynamic(false)
269  , my_exception_name(src.my_exception_name)
270  {}
271 
272  ~movable_exception() throw() {}
273 
275  if ( this != &src ) {
278  }
279  return *this;
280  }
281 
282  ExceptionData& data() throw() { return my_exception_data; }
283 
284  const ExceptionData& data() const throw() { return my_exception_data; }
285 
286  const char* name() const throw() __TBB_override { return my_exception_name; }
287 
288  const char* what() const throw() __TBB_override { return "tbb::movable_exception"; }
289 
292  if ( e ) {
293  ::new (e) movable_exception(*this);
294  ((movable_exception*)e)->my_dynamic = true;
295  }
296  return (movable_exception*)e;
297  }
298  void destroy() throw() __TBB_override {
299  __TBB_ASSERT ( my_dynamic, "Method destroy can be called only on dynamically allocated movable_exceptions" );
300  if ( my_dynamic ) {
301  this->~movable_exception();
303  }
304  }
305  void throw_self() __TBB_override { __TBB_THROW( *this ); }
306 
307 protected:
309  ExceptionData my_exception_data;
310 
311 private:
314 
316 
317  const char* my_exception_name;
318 };
319 
320 #if !TBB_USE_CAPTURED_EXCEPTION
321 namespace internal {
322 
324 
327  std::exception_ptr my_ptr;
328 
329 public:
330  static tbb_exception_ptr* allocate();
331  static tbb_exception_ptr* allocate( const tbb_exception& tag );
334 
336 
337  void destroy() throw();
338 
340  void throw_self() { std::rethrow_exception(my_ptr); }
341 
342 private:
343  tbb_exception_ptr( const std::exception_ptr& src ) : my_ptr(src) {}
346  my_ptr(std::make_exception_ptr(src)) // the final function name in C++11
347  #else
348  my_ptr(std::copy_exception(src)) // early C++0x drafts name
349  #endif
350  {}
351 }; // class tbb::internal::tbb_exception_ptr
352 
353 } // namespace internal
354 #endif /* !TBB_USE_CAPTURED_EXCEPTION */
355 
356 } // namespace tbb
357 
358 #endif /* __TBB_TASK_GROUP_CONTEXT */
359 
360 #endif /* __TBB_exception_H */
Template that can be used to implement exception that transfers arbitrary ExceptionData to the root t...
virtual const char * what() const __TBB_override=0
Returns the result of originally intercepted exception's what() method.
#define __TBB_override
Definition: tbb_stddef.h:244
const char *__TBB_EXPORTED_METHOD name() const __TBB_override
Returns RTTI name of the originally intercepted exception.
const char * what() const __TBB_override
Definition: tbb_misc.cpp:53
const char * what() const __TBB_override
Definition: tbb_misc.cpp:52
#define __TBB_ASSERT(predicate, comment)
No-op version of __TBB_ASSERT.
Definition: tbb_stddef.h:169
captured_exception(const captured_exception &src)
movable_exception * move() __TBB_override
Creates and returns pointer to the deep copy of this exception object.
#define __TBB_THROW(e)
Definition: tbb_stddef.h:289
const char * what() const __TBB_override
Definition: tbb_misc.cpp:55
Exception for missing wait on structured_task_group.
Definition: tbb_exception.h:53
void throw_self() __TBB_override
Throws this exception object.
#define __TBB_MAKE_EXCEPTION_PTR_PRESENT
Definition: tbb_config.h:351
Exception for concurrent containers.
Definition: tbb_exception.h:32
movable_exception(const ExceptionData &data_)
#define private
#define TBB_USE_EXCEPTIONS
Definition: tbb_config.h:477
const char * what() const __TBB_override
Definition: tbb_misc.cpp:54
static tbb_exception_ptr * allocate()
void const char const char int ITT_FORMAT __itt_group_sync p
Interface to be implemented by all exceptions TBB recognizes and propagates across the threads.
const char * my_exception_name
RTTI name of this class.
ExceptionData my_exception_data
User data.
Exception for user-initiated abort.
Definition: tbb_exception.h:47
void throw_exception(exception_id eid)
Versionless convenience wrapper for throw_exception_v4()
captured_exception(const char *name_, const char *info)
__TBB_EXPORTED_METHOD ~captured_exception()
const char * my_exception_name
movable_exception< ExceptionData > self_type
#define __TBB_EXPORTED_METHOD
Definition: tbb_stddef.h:102
void __TBB_EXPORTED_METHOD clear()
const movable_exception & operator=(const movable_exception &src)
void *__TBB_EXPORTED_FUNC allocate_via_handler_v3(size_t n)
Allocates memory using MallocHandler.
const ExceptionData & data() const
captured_exception *__TBB_EXPORTED_METHOD move() __TBB_override
Creates and returns pointer to the deep copy of this exception object.
bool my_dynamic
Flag specifying whether this object has been dynamically allocated (by the move method)
The graph class.
const char * my_exception_info
This class is used by TBB to propagate information about unhandled exceptions into the root thread.
static captured_exception * allocate(const char *name, const char *info)
Functionally equivalent to {captured_exception e(name,info); return e.move();}.
void __TBB_EXPORTED_FUNC throw_bad_last_alloc_exception_v4()
Obsolete.
Definition: tbb_misc.cpp:113
The last enumerator tracks the number of defined IDs. It must remain the last one.
Definition: tbb_exception.h:97
void __TBB_EXPORTED_FUNC deallocate_via_handler_v3(void *p)
Deallocates memory using FreeHandler.
#define __TBB_EXPORTED_FUNC
virtual tbb_exception * move()=0
Creates and returns pointer to the deep copy of this exception object.
void destroy() __TBB_override
Destroys objects created by the move() method.
movable_exception(const movable_exception &src)
const char * what() const __TBB_override
Definition: tbb_misc.cpp:51
const char * name() const __TBB_override
Returns RTTI name of the originally intercepted exception.
void __TBB_EXPORTED_FUNC throw_exception_v4(exception_id)
Gathers all throw operators in one place.
Definition: tbb_misc.cpp:117
ExceptionData & data()
void throw_self()
Throws the contained exception .
const char *__TBB_EXPORTED_METHOD what() const __TBB_override
Returns the result of originally intercepted exception's what() method.
void __TBB_EXPORTED_METHOD set(const char *name, const char *info)
void throw_self() __TBB_override
Throws this exception object.
Exception container that preserves the exact copy of the original exception.
tbb_exception_ptr(const std::exception_ptr &src)
virtual const char * name() const =0
Returns RTTI name of the originally intercepted exception.
virtual void destroy()=0
Destroys objects created by the move() method.
virtual void throw_self()=0
Throws this exception object.
const char * what() const __TBB_override
Returns the result of originally intercepted exception's what() method.
void __TBB_EXPORTED_METHOD destroy() __TBB_override
Destroys objects created by the move() method.
Exception for repeated scheduling of the same task_handle.
Definition: tbb_exception.h:59
void destroy()
Destroys this objects.
tbb_exception_ptr(const captured_exception &src)
Exception for PPL locks.
Definition: tbb_exception.h:41

Copyright © 2005-2019 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.