xref: /oneTBB/include/oneapi/tbb/detail/_exception.h (revision 5fc0a5f6)
1 /*
2     Copyright (c) 2005-2021 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 #include "_config.h"
21 
22 #include <new>          // std::bad_alloc
23 #include <exception>    // std::exception
24 #include <stdexcept>    // std::runtime_error
25 
26 namespace tbb {
27 namespace detail {
28 inline namespace d0 {
29 enum class exception_id {
30     bad_alloc = 1,
31     bad_last_alloc,
32     user_abort,
33     nonpositive_step,
34     out_of_range,
35     reservation_length_error,
36     missing_wait,
37     invalid_load_factor,
38     invalid_key,
39     bad_tagged_msg_cast,
40     unsafe_wait,
41     last_entry
42 };
43 } // namespace d0
44 
45 #if _MSC_VER
46     #pragma warning(disable: 4275)
47 #endif
48 
49 namespace r1 {
50 //! Exception for concurrent containers
51 class TBB_EXPORT bad_last_alloc : public std::bad_alloc {
52 public:
53     const char* __TBB_EXPORTED_METHOD what() const noexcept(true) override;
54 };
55 
56 //! Exception for user-initiated abort
57 class TBB_EXPORT user_abort : public std::exception {
58 public:
59     const char* __TBB_EXPORTED_METHOD what() const noexcept(true) override;
60 };
61 
62 //! Exception for missing wait on structured_task_group
63 class TBB_EXPORT missing_wait : public std::exception {
64 public:
65     const char* __TBB_EXPORTED_METHOD what() const noexcept(true) override;
66 };
67 
68 //! Exception for impossible finalization of task_sheduler_handle
69 class TBB_EXPORT unsafe_wait : public std::runtime_error {
70 public:
unsafe_wait(const char * msg)71     unsafe_wait(const char* msg) : std::runtime_error(msg) {}
72 };
73 
74 //! Gathers all throw operators in one place.
75 /** Its purpose is to minimize code bloat that can be caused by throw operators
76     scattered in multiple places, especially in templates. **/
77 TBB_EXPORT void __TBB_EXPORTED_FUNC throw_exception ( exception_id );
78 } // namespace r1
79 
80 inline namespace d0 {
81 using r1::throw_exception;
82 } // namespace d0
83 
84 } // namespace detail
85 } // namespace tbb
86 
87 #endif // __TBB__exception_H
88 
89