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
192} // namespace original
193
194// ----------------- Definitions of error.h -----------------
195
196template<typename Callback, typename Ret_TYPE, typename... Args_TYPE>
198 if constexpr (constexpr bool is_valid = std::is_invocable_v<Callback, Args_TYPE...>;
199 !is_valid){
201 } else{
202 using result_type = std::invoke_result_t<Callback, Args_TYPE...>;
203 if constexpr (constexpr bool is_valid_return_type = std::is_same_v<result_type, Ret_TYPE>;
204 !is_valid_return_type)
206 }
207}
208
209template <const bool TRIGGERING_CONDITION>
210class original::staticError<original::error, TRIGGERING_CONDITION>
211{
212 static_assert(!TRIGGERING_CONDITION, "A static assert triggered");
213};
214
215template <const bool TRIGGERING_CONDITION>
216class original::staticError<original::outOfBoundError, TRIGGERING_CONDITION>
217{
218 static_assert(!TRIGGERING_CONDITION, "Out of the bound of the object");
219};
220
221template <const bool TRIGGERING_CONDITION>
222class original::staticError<original::valueError, TRIGGERING_CONDITION>
223{
224 static_assert(!TRIGGERING_CONDITION, "Wrong value given");
225};
226
227template <const bool TRIGGERING_CONDITION>
229{
230 static_assert(!TRIGGERING_CONDITION, "Attempting to access null pointer");
231};
232
233template <const bool TRIGGERING_CONDITION>
235{
236 static_assert(!TRIGGERING_CONDITION, "Unsupported Method for class");
237};
238
239template <const bool TRIGGERING_CONDITION>
240class original::staticError<original::noElementError, TRIGGERING_CONDITION>
241{
242 static_assert(!TRIGGERING_CONDITION, "No such element");
243};
244
245template <const bool TRIGGERING_CONDITION>
247{
248 static_assert(!TRIGGERING_CONDITION, "Return type of callback mismatch");
249};
250
251template <const bool TRIGGERING_CONDITION>
253{
254 static_assert(!TRIGGERING_CONDITION, "Callback signature mismatch");
255};
256
257template <const bool TRIGGERING_CONDITION>
258class original::staticError<original::allocateError, TRIGGERING_CONDITION>
259{
260 static_assert(!TRIGGERING_CONDITION, "Can not allocate memory");
261};
262
263#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:197
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
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:157
Main namespace for the project Original.
Definition algorithms.h:21
Type system foundations and concept definitions.