BSplinebasis
Loading...
Searching...
No Matches
BSplineException.h
1/*
2 * ########################################################################
3 * The contents of this file is free and unencumbered software released into the
4 * public domain. For more information, please refer to <http://unlicense.org/>
5 * ########################################################################
6 */
7
8#ifndef BSPLINE_BSPLINEEXCEPTION_H
9#define BSPLINE_BSPLINEEXCEPTION_H
10
11#include <sstream>
12#include <string>
13
20
24enum class ErrorCode {
25 DIFFERING_GRIDS,
26 INCONSISTENT_DATA,
27 MISSING_DATA,
28 INVALID_ACCESS,
29 UNDETERMINED
30};
31
40inline std::string getErrorMessage(ErrorCode errorCode) {
41 switch (errorCode) {
42 case ErrorCode::DIFFERING_GRIDS:
43 return "The requested operation is not implemented for objects defined "
44 "on non-equivalent grids.";
45 case ErrorCode::INCONSISTENT_DATA:
46 return "The data provided is inconsistent.";
47 case ErrorCode::MISSING_DATA:
48 return "Mandatory data was not provided.";
49 case ErrorCode::INVALID_ACCESS:
50 return "Attempted access of nonexistent data.";
51 case ErrorCode::UNDETERMINED:
52 return "The cause of the error is undetermined.";
53 default:
54 return "Errorcode unknown.";
55 }
56}
57
65 switch (errorCode) {
66 case ErrorCode::DIFFERING_GRIDS:
67 return "DIFFERING_GRIDS";
68 case ErrorCode::INCONSISTENT_DATA:
69 return "INCONSISTENT_DATA";
70 case ErrorCode::MISSING_DATA:
71 return "MISSING_DATA";
72 case ErrorCode::INVALID_ACCESS:
73 return "INVALID_ACCESS";
74 case ErrorCode::UNDETERMINED:
75 return "UNDETERMINED";
76 default:
77 return "UNKNOWN_ERRORCODE";
78 }
79}
80
84class BSplineException final : public std::exception {
85 private:
87 ErrorCode _errorCode;
89 std::string _whatString;
90
100 std::string generateWhatString(ErrorCode errorCode,
101 const std::string &message) const {
102 std::stringstream ret;
103 ret << "BSplineException (code: " << getErrorCodeName(errorCode)
104 << "): " << message;
105 return ret.str();
106 };
107
108 public:
115 : _errorCode(errorCode),
116 _whatString(
117 generateWhatString(errorCode, getErrorMessage(errorCode))){};
118
127 : _errorCode(errorCode),
128 _whatString(generateWhatString(errorCode, message)){};
129
135 const char *what() const noexcept override { return _whatString.c_str(); };
136
142 ErrorCode getErrorCode() const { return _errorCode; };
143};
144
145} // namespace bspline::exceptions
146#endif // BSPLINE_BSPLINEEXCEPTION_H
The main exception class.
Definition BSplineException.h:84
const char * what() const noexcept override
Returns a string representation of the exception.
Definition BSplineException.h:135
ErrorCode getErrorCode() const
Returns the error code of this exception.
Definition BSplineException.h:142
BSplineException(ErrorCode errorCode)
Constructs exception with default error message.
Definition BSplineException.h:114
BSplineException(ErrorCode errorCode, std::string message)
Constructs exception with custom error message.
Definition BSplineException.h:126
Represents a global Grid.
Definition Grid.h:27
Exceptions and error codes.
Definition BSplineException.h:19
ErrorCode
The error codes, which may be expected.
Definition BSplineException.h:24
std::string getErrorMessage(ErrorCode errorCode)
Default error messages.
Definition BSplineException.h:40
std::string getErrorCodeName(ErrorCode errorCode)
Returns the errorCode name.
Definition BSplineException.h:64