Legion Runtime
Loading...
Searching...
No Matches
exception.h
Go to the documentation of this file.
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
24#include "legion/api/types.h"
25
26namespace Legion {
27
28 enum ExceptionType {
29 LEGION_APPLICATION_EXCEPTION,
30 LEGION_INTERFACE_EXCEPTION,
31 LEGION_DYNAMIC_TYPE_EXCEPTION,
32 LEGION_PROGRAMMING_MODEL_EXCEPTION,
33 LEGION_MAPPER_EXCEPTION,
34 LEGION_RESOURCE_EXCEPTION,
35 LEGION_STARTUP_EXCEPTION,
36 LEGION_FATAL_EXCEPTION,
37 LEGION_WARNING_EXCEPTION,
38 };
39
50 class Exception : public std::streambuf {
51 public:
52 Exception(ExceptionType type);
53 Exception(const Exception& rhs) = delete;
54 Exception(Exception&& rhs);
55 ~Exception(void);
56 public:
57 Exception& operator=(const Exception& rhs) = delete;
58 Exception& operator=(Exception&& rhs) = delete;
59 public:
60 void clear(void); // Will invalidate any streams
61 void record_backtrace(const Realm::Backtrace& backtrace);
62 public:
63 size_t size(void) const;
64 const char* data(void) const;
65 // Can convert implicitly to a std::stringview
66 inline operator std::string_view(void) const
67 {
68 return std::string_view(data(), size());
69 }
70 protected:
71 virtual int_type overflow(int_type c) override;
72 public:
73 const ExceptionType type;
74 private:
75 static constexpr size_t STACK_SIZE = 128;
76 static_assert(sizeof(char) == sizeof(uint8_t));
77 char stack_buffer[STACK_SIZE];
78 char* heap_buffer;
79 size_t heap_size;
80 };
81
87 class Error {
88 public:
89 Error(ExceptionType type = LEGION_APPLICATION_EXCEPTION);
90 Error(const Error& rhs) = delete;
91 Error(Error&& rhs) = delete;
92 ~Error(void);
93 public:
94 Error& operator=(const Error& rhs) = delete;
95 Error& operator=(Error&& rhs) = delete;
96 public:
97 template<typename T>
98 inline Error& operator<<(T&& value)
99 {
100 stream << std::forward<T>(value);
101 return *this;
102 }
103 [[noreturn]] void raise(void);
104 public:
105 Exception exception;
106 std::ostream stream;
107 private:
108 bool raised;
109 };
110
116 class Fatal {
117 public:
118 Fatal(void);
119 Fatal(const Fatal& rhs) = delete;
120 Fatal(Fatal&& rhs) = delete;
121 ~Fatal(void);
122 public:
123 Fatal& operator=(const Fatal& rhs) = delete;
124 Fatal& operator=(Fatal&& rhs) = delete;
125 public:
126 template<typename T>
127 inline Fatal& operator<<(T&& value)
128 {
129 stream << std::forward<T>(value);
130 return *this;
131 }
132 [[noreturn]] void raise(void);
133 public:
134 Exception exception;
135 std::ostream stream;
136 private:
137 bool raised;
138 };
139
145 class Warning {
146 public:
147 Warning(void);
148 Warning(const Warning& rhs) = delete;
149 Warning(Warning&& rhs) = delete;
150 ~Warning(void);
151 public:
152 Warning& operator=(const Warning& rhs) = delete;
153 Warning& operator=(Warning&& rhs) = delete;
154 public:
155 template<typename T>
156 inline Warning& operator<<(T&& value)
157 {
158 stream << std::forward<T>(value);
159 return *this;
160 }
161 void raise(void);
162 public:
163 Exception exception;
164 std::ostream stream;
165 bool active;
166 };
167
176 public:
177 virtual ~ExceptionHandler(void) { }
178 // Whether this exception handler can handle exceptions or
179 // is only capable of handling warnings
180 virtual bool can_handle(ExceptionType type) const { return false; }
181 // Handle the kind of the exception and return if the exception
182 // was successfaully handled
183 virtual bool handle_exception(
184 Exception& exception, const std::string_view& provenance,
185 const Realm::Backtrace& backtrace)
186 {
187 return false;
188 }
189 };
190
191} // namespace Legion
192
193#endif // __LEGION_EXCEPTION_H__
Definition exception.h:87
Definition exception.h:175
Definition exception.h:50
Definition exception.h:116
Definition exception.h:145
Definition accessors.h:29