NeoN
WIP Prototype of a modern OpenFOAM core
Loading...
Searching...
No Matches
exceptions.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: MIT
2// SPDX-FileCopyrightText: 2023 NeoN authors
3#pragma once
4
6
7namespace NeoN
8{
25class Error : public std::exception
26{
27public:
28
36 Error(const std::string& file, int line, const std::string& what)
37 : what_(file + ":" + std::to_string(line) + ": " + what)
38 {}
39
44 virtual const char* what() const noexcept override { return what_.c_str(); }
45
46private:
47
48 const std::string what_;
49};
50
51
61{
62public:
63
75 const std::string& file,
76 int line,
77 const std::string& func,
78 localIdx lengthA,
79 localIdx lengthB,
80 const std::string& clarification
81 )
82 : Error(
83 file,
84 line,
85 func + ": Trying to perform binary operation " + " " + std::to_string(lengthA) + ", "
86 + std::to_string(lengthB) + " " + clarification
87 )
88 {}
89};
90
91
98#define NeoN_ASSERT_EQUAL_LENGTH(_op1, _op2) \
99 auto s1 = static_cast<localIdx>(_op1.size()); \
100 auto s2 = static_cast<localIdx>(_op2.size()); \
101 if (s1 != s2) \
102 { \
103 throw ::NeoN::DimensionMismatch( \
104 __FILE__, __LINE__, __func__, s1, s2, "expected equal dimensions" \
105 ); \
106 }
107}
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
int32_t localIdx
Definition label.hpp:30