4#ifndef SVMP_FE_EXCEPTION_H
5#define SVMP_FE_EXCEPTION_H
28 StatusCode status = StatusCode::Unknown,
29 const char* file =
"",
31 const char* function =
"")
44 const char* function =
"")
45 :
FEException(message, StatusCode::Unknown, file, line, function)
49 StatusCode status()
const noexcept {
return status_code(); }
55 const char* file =
"",
57 const char* function =
"")
58 :
FEException(message, StatusCode::InvalidArgument, file, line,
67 std::string element_type =
"",
68 const char* file =
"",
70 const char* function =
"")
72 StatusCode::InvalidArgument,
76 element_type_(std::move(element_type))
80 const std::string& element_type()
const noexcept {
return element_type_; }
83 static std::string build_message(
const std::string& message,
84 const std::string& element_type)
86 if (element_type.empty()) {
90 return message +
" (Element type: " + element_type +
")";
93 std::string element_type_;
99 long long dof_index = invalid_dof_index(),
100 const char* file =
"",
102 const char* function =
"")
104 StatusCode::InvalidArgument,
108 dof_index_(dof_index)
112 long long dof_index()
const noexcept {
return dof_index_; }
113 static constexpr long long invalid_dof_index()
noexcept {
return -1; }
116 static std::string build_message(
const std::string& message,
119 if (dof_index == invalid_dof_index()) {
123 return message +
" (DOF index: " + std::to_string(dof_index) +
")";
126 long long dof_index_ = invalid_dof_index();
132 const char* file =
"",
134 const char* function =
"")
135 :
FEException(message, StatusCode::InvalidState, file, line, function)
143 std::string backend_name =
"",
145 const char* file =
"",
147 const char* function =
"")
148 :
FEException(build_message(message, backend_name, error_code),
149 StatusCode::DependencyError,
153 backend_name_(std::move(backend_name)),
154 error_code_(error_code)
158 const std::string& backend_name()
const noexcept {
return backend_name_; }
159 int error_code()
const noexcept {
return error_code_; }
162 static std::string build_message(
const std::string& message,
163 const std::string& backend_name,
166 std::ostringstream oss;
168 if (!backend_name.empty() || error_code != 0) {
170 if (!backend_name.empty()) {
171 oss <<
"Backend: " << backend_name;
173 if (error_code != 0) {
174 if (!backend_name.empty()) {
177 oss <<
"Error code: " << error_code;
184 std::string backend_name_;
191 const char* file =
"",
193 const char* function =
"")
194 :
FEException(
"Feature not implemented: " + feature,
195 StatusCode::NotImplemented,
208 const char *function =
"")
209 :
FEException(
"Missing initialization: " + feature,
210 StatusCode::InvalidState,
222 double residual = 0.0,
223 const char* file =
"",
225 const char* function =
"")
226 :
FEException(build_message(message, iteration, residual),
227 StatusCode::InvalidState,
231 iteration_(iteration),
236 int iteration()
const noexcept {
return iteration_; }
237 double residual()
const noexcept {
return residual_; }
240 static std::string build_message(
const std::string& message,
244 std::ostringstream oss;
246 if (iteration >= 0) {
247 oss <<
" (Iteration: " << iteration;
248 if (residual > 0.0) {
249 oss <<
", Residual: " << residual;
257 double residual_ = 0.0;
263 double jacobian_det = 0.0,
264 const char* file =
"",
266 const char* function =
"")
267 :
FEException(build_message(message, jacobian_det),
268 StatusCode::InvalidState,
272 jacobian_det_(jacobian_det)
276 double jacobian_det()
const noexcept {
return jacobian_det_; }
279 static std::string build_message(
const std::string& message,
double det)
281 return message +
" (Jacobian determinant: " + std::to_string(det) +
285 double jacobian_det_ = 0.0;
288template <
class ExceptionT,
class... Args>
289[[noreturn]]
inline void raise(
SourceLocation location, Args&&... args)
291 ::svmp::raise<ExceptionT>(location, std::forward<Args>(args)...);
294template <
class ExceptionT = FEException,
class... Args>
295inline void throw_if(
bool condition,
SourceLocation location, Args&&... args)
298 ::svmp::FE::raise<ExceptionT>(location, std::forward<Args>(args)...);
302template <
class ExceptionT = InvalidArgumentException,
class... Args>
303inline void check_arg(
bool condition, SourceLocation location, Args&&... args)
305 ::svmp::check_arg<ExceptionT>(condition, location,
306 std::forward<Args>(args)...);
309template <
class ExceptionT = InvalidArgumentException,
class PointerT,
311inline void check_not_null(PointerT ptr, SourceLocation location,
314 ::svmp::check_not_null<ExceptionT>(ptr, location, std::forward<Args>(args)...);
317template <
class ExceptionT = InvalidArgumentException,
class IndexT,
319inline void check_index(IndexT index, SizeT size, SourceLocation location)
321 const long long fe_check_index_value =
static_cast<long long>(index);
322 const long long fe_check_size_value =
static_cast<long long>(size);
324 ::svmp::FE::check_arg<ExceptionT>(
325 fe_check_index_value >= 0 &&
326 fe_check_index_value < fe_check_size_value,
328 "Index " + std::to_string(fe_check_index_value) +
329 " out of bounds [0, " + std::to_string(fe_check_size_value) +
")");
332[[noreturn]]
inline void not_implemented(
const std::string& feature,
333 SourceLocation location)
335 ::svmp::FE::raise<NotImplementedException>(location, feature);
Definition Exception.h:271
Definition FEException.h:129
Definition FEException.h:140
Definition FEException.h:218
Definition FEException.h:96
Definition FEException.h:25
Definition FEException.h:52
Definition FEException.h:64
Definition FEException.h:188
Definition FEException.h:203
Definition FEException.h:260
Definition Exception.h:70