NeoN
A framework for CFD software
Loading...
Searching...
No Matches
exceptions.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2023 - 2025 NeoN authors
2//
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
8
9namespace NeoN
10{
27class Error : public std::exception
28{
29public:
30
38 Error(const std::string& file, int line, const std::string& what)
39 : what_(file + ":" + std::to_string(line) + ": " + what)
40 {}
41
46 virtual const char* what() const noexcept override { return what_.c_str(); }
47
48private:
49
50 const std::string what_;
51};
52
53
63{
64public:
65
77 const std::string& file,
78 int line,
79 const std::string& func,
80 localIdx lengthA,
81 localIdx lengthB,
82 const std::string& clarification
83 )
84 : Error(
85 file,
86 line,
87 func + ": Trying to perform binary operation " + " " + std::to_string(lengthA) + ", "
88 + std::to_string(lengthB) + " " + clarification
89 )
90 {}
91};
92
93
100#define NeoN_ASSERT_EQUAL_LENGTH(_op1, _op2) \
101 auto s1 = static_cast<localIdx>(_op1.size()); \
102 auto s2 = static_cast<localIdx>(_op2.size()); \
103 if (s1 != s2) \
104 { \
105 throw ::NeoN::DimensionMismatch( \
106 __FILE__, __LINE__, __func__, s1, s2, "expected equal dimensions" \
107 ); \
108 }
109}
Error for handling two containers of incompatible lengths.
DimensionMismatch(const std::string &file, int line, const std::string &func, localIdx lengthA, localIdx lengthB, const std::string &clarification)
Base class for consistent error representation.
Error(const std::string &file, int line, const std::string &what)
virtual const char * what() const noexcept override
Definition array.hpp:20
int32_t localIdx
Definition label.hpp:32