ORIGINAL
Loading...
Searching...
No Matches
error.h
Go to the documentation of this file.
1#ifndef ERROR_H
2#define ERROR_H
3#include <exception>
4#include "types.h"
5
12
13namespace original {
14
22 public:
37 template<typename Callback, typename Ret_TYPE, typename ...Args_TYPE>
38 static void check();
39 };
40
50 class error : public std::exception{};
51
70 template<typename ERR, const bool TRIGGERING_CONDITION>
73 {
74 static_assert(!TRIGGERING_CONDITION);
75 };
76
77// ----------------- Exception Classes -----------------
78
84class outOfBoundError final : public error {
85public:
86 [[nodiscard]] auto what() const noexcept -> const char* override
87 {
88 return "Out of the bound of the object.";
89 }
90};
91
97class valueError final : public error {
98public:
99 [[nodiscard]] auto what() const noexcept -> const char* override
100 {
101 return "Wrong value given.";
102 }
103};
104
110class nullPointerError final : public error {
111public:
112 [[nodiscard]] auto what() const noexcept -> const char* override
113 {
114 return "Attempting to access null pointer.";
115 }
116};
117
123class unSupportedMethodError final : public error {
124public:
125 [[nodiscard]] auto what() const noexcept -> const char* override
126 {
127 return "Unsupported Method for class.";
128 }
129};
130
136class noElementError final : public error {
137public:
138 [[nodiscard]] auto what() const noexcept -> const char* override
139 {
140 return "No such element.";
141 }
142};
143
149class callbackSignatureError final : public error {
150public:
151 [[nodiscard]] auto what() const noexcept -> const char* override
152 {
153 return "Callback signature mismatch.";
154 }
155};
156
162class callbackReturnTypeError final : public error {
163public:
164 [[nodiscard]] auto what() const noexcept -> const char* override
165 {
166 return "Return type of callback mismatch.";
167 }
168};
169
183class allocateError final : public error
184{
185 public:
186 [[nodiscard]] auto what() const noexcept -> const char* override
187 {
188 return "Can not allocate memory.";
189 }
190};
191
192class sysError final : public error
193{
194public:
195 [[nodiscard]] auto what() const noexcept -> const char* override
196 {
197 return "A sys error triggered.";
198 }
199};
200
201} // namespace original
202
203// ----------------- Definitions of error.h -----------------
204
205template<typename Callback, typename Ret_TYPE, typename... Args_TYPE>
207 if constexpr (constexpr bool is_valid = std::is_invocable_v<Callback, Args_TYPE...>;
208 !is_valid){
210 } else{
211 using result_type = std::invoke_result_t<Callback, Args_TYPE...>;
212 if constexpr (constexpr bool is_valid_return_type = std::is_same_v<result_type, Ret_TYPE>;
213 !is_valid_return_type)
215 }
216}
217
218template <const bool TRIGGERING_CONDITION>
219class original::staticError<original::error, TRIGGERING_CONDITION>
220{
221 static_assert(!TRIGGERING_CONDITION, "A static assert triggered");
222};
223
224template <const bool TRIGGERING_CONDITION>
225class original::staticError<original::outOfBoundError, TRIGGERING_CONDITION>
226{
227 static_assert(!TRIGGERING_CONDITION, "Out of the bound of the object");
228};
229
230template <const bool TRIGGERING_CONDITION>
231class original::staticError<original::valueError, TRIGGERING_CONDITION>
232{
233 static_assert(!TRIGGERING_CONDITION, "Wrong value given");
234};
235
236template <const bool TRIGGERING_CONDITION>
238{
239 static_assert(!TRIGGERING_CONDITION, "Attempting to access null pointer");
240};
241
242template <const bool TRIGGERING_CONDITION>
244{
245 static_assert(!TRIGGERING_CONDITION, "Unsupported Method for class");
246};
247
248template <const bool TRIGGERING_CONDITION>
249class original::staticError<original::noElementError, TRIGGERING_CONDITION>
250{
251 static_assert(!TRIGGERING_CONDITION, "No such element");
252};
253
254template <const bool TRIGGERING_CONDITION>
256{
257 static_assert(!TRIGGERING_CONDITION, "Return type of callback mismatch");
258};
259
260template <const bool TRIGGERING_CONDITION>
262{
263 static_assert(!TRIGGERING_CONDITION, "Callback signature mismatch");
264};
265
266template <const bool TRIGGERING_CONDITION>
267class original::staticError<original::allocateError, TRIGGERING_CONDITION>
268{
269 static_assert(!TRIGGERING_CONDITION, "Can not allocate memory");
270};
271
272#endif // ERROR_H
Exception for memory allocation failures.
Definition error.h:184
Static utility for validating callback signatures.
Definition error.h:21
static void check()
Validates a callback's signature and return type.
Definition error.h:206
Exception for callback return type mismatch.
Definition error.h:162
Exception for callback argument mismatch.
Definition error.h:149
Base interface for all exception types in Original.
Definition error.h:50
Exception for missing element requests.
Definition error.h:136
Exception for null pointer dereference attempts.
Definition error.h:110
Exception for container index out-of-range errors.
Definition error.h:84
Compile-time error assertion utility.
Definition error.h:73
Definition error.h:193
Exception for unimplemented method calls.
Definition error.h:123
Exception for invalid parameter values.
Definition error.h:97
Checks derivation or type identity.
Definition types.h:173
Main namespace for the project Original.
Definition algorithms.h:21
Core type system foundations and concept definitions.