NeoFOAM
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 NeoFOAM authors
3#pragma once
4
5namespace NeoFOAM
6{
23class Error : public std::exception
24{
25public:
26
34 Error(const std::string& file, int line, const std::string& what)
35 : what_(file + ":" + std::to_string(line) + ": " + what)
36 {}
37
42 virtual const char* what() const noexcept override { return what_.c_str(); }
43
44private:
45
46 const std::string what_;
47};
48
49
59{
60public:
61
73 const std::string& file,
74 int line,
75 const std::string& func,
76 size_t lengthA,
77 size_t lengthB,
78 const std::string& clarification
79 )
80 : Error(
81 file,
82 line,
83 func + ": Trying to perform binary operation " + " " + std::to_string(lengthA) + ", "
84 + std::to_string(lengthB) + " " + clarification
85 )
86 {}
87};
88
89
96#define NeoFOAM_ASSERT_EQUAL_LENGTH(_op1, _op2) \
97 if (_op1.size() != _op2.size()) \
98 { \
99 throw ::NeoFOAM::DimensionMismatch( \
100 __FILE__, __LINE__, __func__, _op1.size(), _op2.size(), "expected equal dimensions" \
101 ); \
102 }
103}
Error for handling two containers of incompatible lengths.
DimensionMismatch(const std::string &file, int line, const std::string &func, size_t lengthA, size_t lengthB, const std::string &clarification)
Base class for consistent error representation.
virtual const char * what() const noexcept override
Error(const std::string &file, int line, const std::string &what)