Legion Runtime
Loading...
Searching...
No Matches
exception.h
1/* Copyright 2026 Stanford University, NVIDIA Corporation
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef __LEGION_EXCEPTION_H__
17#define __LEGION_EXCEPTION_H__
18
19#include "legion/api/types.h"
20
21namespace Legion {
22
23 enum ExceptionType {
24 LEGION_APPLICATION_EXCEPTION,
25 LEGION_INTERFACE_EXCEPTION,
26 LEGION_DYNAMIC_TYPE_EXCEPTION,
27 LEGION_PROGRAMMING_MODEL_EXCEPTION,
28 LEGION_MAPPER_EXCEPTION,
29 LEGION_RESOURCE_EXCEPTION,
30 LEGION_STARTUP_EXCEPTION,
31 LEGION_FATAL_EXCEPTION,
32 LEGION_WARNING_EXCEPTION,
33 };
34
45 class Exception : public std::streambuf {
46 public:
47 Exception(ExceptionType type);
48 Exception(const Exception& rhs) = delete;
49 Exception(Exception&& rhs);
50 ~Exception(void);
51 public:
52 Exception& operator=(const Exception& rhs) = delete;
53 Exception& operator=(Exception&& rhs) = delete;
54 public:
55 void clear(void); // Will invalidate any streams
56 void record_backtrace(const Realm::Backtrace& backtrace);
57 public:
58 size_t size(void) const;
59 const char* data(void) const;
60 // Can convert implicitly to a std::stringview
61 inline operator std::string_view(void) const
62 {
63 return std::string_view(data(), size());
64 }
65 protected:
66 virtual int_type overflow(int_type c) override;
67 public:
68 const ExceptionType type;
69 private:
70 static constexpr size_t STACK_SIZE = 128;
71 static_assert(sizeof(char) == sizeof(uint8_t));
72 char stack_buffer[STACK_SIZE];
73 char* heap_buffer;
74 size_t heap_size;
75 };
76
82 class Error {
83 public:
84 Error(ExceptionType type = LEGION_APPLICATION_EXCEPTION);
85 Error(const Error& rhs) = delete;
86 Error(Error&& rhs) = delete;
87 ~Error(void);
88 public:
89 Error& operator=(const Error& rhs) = delete;
90 Error& operator=(Error&& rhs) = delete;
91 public:
92 template<typename T>
93 inline Error& operator<<(T&& value)
94 {
95 stream << std::forward<T>(value);
96 return *this;
97 }
98 [[noreturn]] void raise(void);
99 public:
100 Exception exception;
101 std::ostream stream;
102 private:
103 bool raised;
104 };
105
111 class Fatal {
112 public:
113 Fatal(void);
114 Fatal(const Fatal& rhs) = delete;
115 Fatal(Fatal&& rhs) = delete;
116 ~Fatal(void);
117 public:
118 Fatal& operator=(const Fatal& rhs) = delete;
119 Fatal& operator=(Fatal&& rhs) = delete;
120 public:
121 template<typename T>
122 inline Fatal& operator<<(T&& value)
123 {
124 stream << std::forward<T>(value);
125 return *this;
126 }
127 [[noreturn]] void raise(void);
128 public:
129 Exception exception;
130 std::ostream stream;
131 private:
132 bool raised;
133 };
134
140 class Warning {
141 public:
142 Warning(void);
143 Warning(const Warning& rhs) = delete;
144 Warning(Warning&& rhs) = delete;
145 ~Warning(void);
146 public:
147 Warning& operator=(const Warning& rhs) = delete;
148 Warning& operator=(Warning&& rhs) = delete;
149 public:
150 template<typename T>
151 inline Warning& operator<<(T&& value)
152 {
153 stream << std::forward<T>(value);
154 return *this;
155 }
156 void raise(void);
157 public:
158 Exception exception;
159 std::ostream stream;
160 bool active;
161 };
162
171 public:
172 virtual ~ExceptionHandler(void) { }
173 // Whether this exception handler can handle exceptions or
174 // is only capable of handling warnings
175 virtual bool can_handle(ExceptionType type) const { return false; }
176 // Handle the kind of the exception and return if the exception
177 // was successfaully handled
178 virtual bool handle_exception(
179 Exception& exception, const std::string_view& provenance,
180 const Realm::Backtrace& backtrace)
181 {
182 return false;
183 }
184 };
185
186} // namespace Legion
187
188#endif // __LEGION_EXCEPTION_H__
Definition exception.h:82
Definition exception.h:170
Definition exception.h:45
Definition exception.h:111
Definition exception.h:140