30#include "MeshKernel/Constants.hpp"
31#include "MeshKernel/Definitions.hpp"
32#include "MeshKernel/Formatting.hpp"
36#include <source_location>
42#define STRINGIFY(str) #str
43#define TO_STR_LITERAL(str) STRINGIFY(str)
75 m_exit_code{exit_code}
81 [[nodiscard]] std::string_view
Name()
const {
return m_name; }
88 std::string_view m_name;
100 std::source_location
const& source_location = std::source_location::current())
101 : m_format_string(format_string),
102 m_source_location(source_location)
110 std::source_location
const& source_location = std::source_location::current())
111 : m_format_string(message),
112 m_source_location(source_location)
120 std::source_location
const& source_location = std::source_location::current())
121 : m_format_string(message),
122 m_source_location(source_location)
128 [[nodiscard]] std::string_view
String()
const {
return m_format_string; }
132 [[nodiscard]] std::source_location
const&
SourceLocation()
const {
return m_source_location; }
135 std::string_view m_format_string;
137 std::source_location m_source_location;
147 template <
typename... Args>
150 m_source_location(format_string.SourceLocation())
152 if (
sizeof...(args) == 0)
154 m_formatted_message = format_string.
String();
158 m_formatted_message = fmt_ns::vformat(format_string.
String(), fmt_ns::make_format_args(args...));
167 const char*
what() const noexcept
override
169#if HAVE_SRC_LOC_IN_ERR_MSGS
170 m_what = fmt_ns::format(
"Exception of type '{}' in {} ({}:{}) {}: {}\n",
173 m_source_location.line(),
174 m_source_location.column(),
175 m_source_location.function_name(),
178 m_what = fmt_ns::format(
"Exception of type '{}': {}\n",
182 return m_what.c_str();
167 const char*
what() const noexcept
override {
…}
201 std::string m_formatted_message;
203 mutable std::string m_what;
205 std::source_location m_source_location;
209 [[nodiscard]] std::string StrippedFilePath()
const
211 std::string path = m_source_location.file_name();
213 std::string path_to_erase(TO_STR_LITERAL(CMAKE_SRC_DIR));
215 std::replace(path_to_erase.begin(), path_to_erase.end(),
'/',
'\\');
217 if (
size_t pos = path.find(path_to_erase); pos != std::string::npos)
220 path.erase(pos, path_to_erase.length() + 1);
222 std::replace(path.begin(), path.end(),
'\\',
'/');
290 template <
typename... Args>
296 m_mesh_index(mesh_index),
297 m_mesh_location(mesh_location)
318 [[nodiscard]] std::string FormattedMessage()
const override
320 return fmt_ns::format(
"Error occurred at index {} (location: {}). {}",
322 LocationToString.at(m_mesh_location),
A class for throwing algorithm exceptions.
Definition Exceptions.hpp:248
An exception class thrown when an attempt is made that violates a range constraint.
Definition Exceptions.hpp:267
Contains error category information.
Definition Exceptions.hpp:67
ErrorCategory(std::string_view name, ExitCode exit_code)
Class constructor.
Definition Exceptions.hpp:72
std::string_view Name() const
Returns the name of the error category.
Definition Exceptions.hpp:81
ExitCode Code() const
Return the exit code of the error category.
Definition Exceptions.hpp:85
A class for throwing linear algebra exceptions.
Definition Exceptions.hpp:332
A class for throwing mesh geometry errors.
Definition Exceptions.hpp:283
Location MeshLocation() const
Returns the mesh location.
Definition Exceptions.hpp:307
MeshGeometryError(meshkernel::UInt mesh_index, Location mesh_location, FormatString const &format_string, Args &&... args)
Class constructor.
Definition Exceptions.hpp:291
meshkernel::UInt MeshIndex() const
Returns the invalid index.
Definition Exceptions.hpp:303
A class for throwing general MeshKernel exceptions.
Definition Exceptions.hpp:142
const char * what() const noexcept override
Returns the explanatory string of the error.
Definition Exceptions.hpp:167
virtual ~MeshKernelError()=default
Class destructor.
virtual std::string FormattedMessage() const
Returns the message.
Definition Exceptions.hpp:198
MeshKernelError(FormatString const &format_string, Args &&... args)
Class constructor.
Definition Exceptions.hpp:148
ExitCode Code() const
Returns the exit code.
Definition Exceptions.hpp:187
virtual ErrorCategory Category() const
Returns the error category.
Definition Exceptions.hpp:192
A class for throwing not implemented exceptions.
Definition Exceptions.hpp:232
A class for throwing range error exceptions.
Definition Exceptions.hpp:348
Contains the logic of the C++ static library.
Definition AveragingInterpolation.hpp:37
ExitCode
Enumeration of exit codes.
Definition Exceptions.hpp:52
@ MeshGeometryErrorCode
Geometry error.
Definition Exceptions.hpp:58
@ Success
Success.
Definition Exceptions.hpp:53
@ StdLibExceptionCode
Standrad library exception.
Definition Exceptions.hpp:61
@ NotImplementedErrorCode
Not implemented error.
Definition Exceptions.hpp:55
@ UnknownExceptionCode
Unknown exception.
Definition Exceptions.hpp:62
@ RangeErrorCode
Range error.
Definition Exceptions.hpp:60
@ AlgorithmErrorCode
Algorithm error.
Definition Exceptions.hpp:56
@ LinearAlgebraErrorCode
Linear algebra error.
Definition Exceptions.hpp:59
@ MeshKernelErrorCode
MehKernel error.
Definition Exceptions.hpp:54
@ ConstraintErrorCode
Constraint error.
Definition Exceptions.hpp:57
Location
Mesh locations enumeration.
Definition Definitions.hpp:76
std::uint32_t UInt
Integer type used when indexing mesh graph entities.
Definition Definitions.hpp:39