DPC++ Runtime
Runtime libraries for oneAPI DPC++
exception_list.hpp
Go to the documentation of this file.
1 //==---------------- exception_list.hpp - SYCL exception_list --------------==//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #pragma once
10 
11 // 4.9.2 Exception Class Interface
12 
13 #include <sycl/detail/export.hpp> // for __SYCL_EXPORT
14 #include <sycl/detail/iostream_proxy.hpp> // for cerr
15 
16 #include <cstddef> // for size_t
17 #include <exception> // for exception_ptr, exception
18 #include <ostream> // for operator<<, basic_ostream
19 #include <vector> // for vector
20 
21 namespace sycl {
22 inline namespace _V1 {
23 
24 // Forward declaration
25 namespace detail {
26 class queue_impl;
27 }
28 
32 class __SYCL_EXPORT exception_list {
33 public:
34  using value_type = std::exception_ptr;
35  using reference = value_type &;
36  using const_reference = const value_type &;
37  using size_type = std::size_t;
38  using iterator = std::vector<std::exception_ptr>::const_iterator;
39  using const_iterator = std::vector<std::exception_ptr>::const_iterator;
40 
41  size_type size() const;
42  // first asynchronous exception
43  iterator begin() const;
44  // refer to past-the-end last asynchronous exception
45  iterator end() const;
46 
47 private:
48  friend class detail::queue_impl;
49  void PushBack(const_reference Value);
50  void PushBack(value_type &&Value);
51  void Clear() noexcept;
52  std::vector<std::exception_ptr> MList;
53 };
54 
55 namespace detail {
56 // Default implementation of async_handler used by queue and context when no
57 // user-defined async_handler is specified.
58 inline void defaultAsyncHandler(exception_list Exceptions) {
59  std::cerr << "Default async_handler caught exceptions:";
60  for (auto &EIt : Exceptions) {
61  try {
62  if (EIt) {
63  std::rethrow_exception(EIt);
64  }
65  } catch (const std::exception &E) {
66  std::cerr << "\n\t" << E.what();
67  }
68  }
69  std::cerr << std::endl;
70  std::terminate();
71 }
72 } // namespace detail
73 } // namespace _V1
74 } // namespace sycl
A list of asynchronous exceptions.
std::vector< std::exception_ptr >::const_iterator iterator
const value_type & const_reference
std::vector< std::exception_ptr >::const_iterator const_iterator
std::exception_ptr value_type
__SYCL_EXTERN_STREAM_ATTRS ostream cerr
Linked to standard error (unbuffered)
void defaultAsyncHandler(exception_list Exceptions)
Definition: access.hpp:18
_Abi const simd< _Tp, _Abi > & noexcept
Definition: simd.hpp:1324