handlers.hpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9 ** Ifdefs
10 *****************************************************************************/
11 
12 #ifndef ECL_ERRORS_HANDLERS_HPP_
13 #define ECL_ERRORS_HANDLERS_HPP_
14 
15 /*****************************************************************************
16 ** Includes
17 *****************************************************************************/
18 
19 #include <ecl/config/macros.hpp>
20 #include <cstring>
21 #include <cstdio>
22 #include "macros.hpp"
23 #include "flags.hpp"
24 
25 /*****************************************************************************
26 ** Namespaces
27 *****************************************************************************/
28 
29 namespace ecl {
30 
59 public:
65  Error(const ErrorFlag& flag = UnknownError) : error_flag(flag) {}
66  virtual ~Error() {}
67 
72  virtual ErrorFlag flag() const { return error_flag; }
73  virtual void operator=(const ErrorFlag &error) { error_flag = error; }
74 
75 // virtual void debug(const char* loc) {
76 // #if !defined(NDEBUG) && !defined(ECL_NDEBUG)
77 // printf("%s - %s\n",loc,what());
78 // #endif
79 // }
80 
94  virtual void print(const char* loc) {
95  printf("%s - %s\n",loc,what());
96  }
97 
103  virtual const char* what() const {
104  switch (error_flag) {
105  case (NoError) : { return noErrorString(); }
106  case (OutOfRangeError) : { return outOfRangeErrorString(); }
107  case (ConstructorError) : { return constructorErrorString(); }
108  case (DestructorError) : { return destructorErrorString(); }
109  case (ConversionError) : { return conversionErrorString(); }
110  case (OpenError) : { return openErrorString(); }
111  case (CloseError) : { return closeErrorString(); }
112  case (InvalidArgError) : { return invalidArgErrorString(); }
113  case (ConfigurationError) : { return configurationErrorString(); }
114  case (ConnectionError) : { return connectErrorString(); }
115  case (ReadError) : { return readErrorString(); }
116  case (WriteError) : { return writeErrorString(); }
117  case (NotInitialisedError) : { return notInitialisedErrorString(); }
118  case (PermissionsError) : { return permissionsErrorString(); }
119  case (MemoryError) : { return memoryErrorString(); }
120  case (UsageError) : { return usageErrorString(); }
121  case (RaiiError) : { return raiiErrorString(); }
122  case (ArgNotSupportedError) : { return argNotSupportedErrorString(); }
123  case (NotSupportedError) : { return notSupportedErrorString(); }
124  case (BusyError) : { return busyErrorString(); }
125  case (OutOfResourcesError) : { return outOfResourcesErrorString(); }
126  case (InterruptedError) : { return interruptedErrorString(); }
127  case (BlockingError) : { return blockingErrorString(); }
128  case (SystemFailureError) : { return systemFailureErrorString(); }
129  case (InvalidObjectError) : { return invalidObjectErrorString(); }
130  case (IsLockedError) : { return isLockedErrorString(); }
131  case (TimeOutError) : { return isTimeOutErrorString(); }
132  case (NotFoundError) : { return notFoundErrorString(); }
133  case (ConnectionRefusedError) : { return connectionRefusedString(); }
134 
135  default : { return unknownErrorString(); } // also covers the 'UnknownError flag.
136  }
137  }
138 protected:
139  virtual const char* noErrorString() const { return "No error."; }
140  virtual const char* outOfRangeErrorString() const { return "Out of range error - tried to access beyond the range of the object (usually container)."; }
141  virtual const char* constructorErrorString() const { return "The constructor did not produce a valid object."; }
142  virtual const char* destructorErrorString() const { return "The destructor failed to self destruct."; }
143  virtual const char* conversionErrorString() const { return "Conversion from one type to another failed."; }
144  virtual const char* openErrorString() const { return "Could not open the requested object."; }
145  virtual const char* closeErrorString() const { return "Could not close the requested object."; }
146  virtual const char* invalidArgErrorString() const { return "One of the supplied input arguments was invalid."; }
147  virtual const char* configurationErrorString() const { return "There was a configuration error."; }
148  virtual const char* connectErrorString() const { return "Could not connect."; }
149  virtual const char* readErrorString() const { return "Could not read from the object."; }
150  virtual const char* writeErrorString() const { return "Could not write to the object."; }
151  virtual const char* notInitialisedErrorString() const { return "The object has not been properly initialised yet."; }
152  virtual const char* permissionsErrorString() const { return "The caller does not have the required permissions."; }
153  virtual const char* memoryErrorString() const { return "There was a problem allocating the requested memory."; }
154  virtual const char* usageErrorString() const { return "The object was used incorrectly."; }
155  virtual const char* raiiErrorString() const { return "The object is pure RAII style and must be initialised correctly, you may not use the default constructor."; }
156  virtual const char* argNotSupportedErrorString() const { return "The combination of input arguments is not supported on this platform."; }
157  virtual const char* notSupportedErrorString() const { return "This operation is not supported on this platform."; }
158  virtual const char* busyErrorString() const { return "Resources are busy, operation is not permitted"; }
159  virtual const char* outOfResourcesErrorString() const { return "Out of resources, cannot proceed."; }
160  virtual const char* interruptedErrorString() const { return "This operation was interrupted."; }
161  virtual const char* blockingErrorString() const { return "A device marked as blocking, but used as non-blocking, or vice versa."; }
162  virtual const char* systemFailureErrorString() const { return "A subsystem has failed mid operation."; }
163  virtual const char* invalidObjectErrorString() const { return "Attempted to work on an invalid object."; }
164  virtual const char* isLockedErrorString() const { return "Invalidates attempts to work further because an object is locked."; }
165  virtual const char* isTimeOutErrorString() const { return "A timeout occured."; }
166  virtual const char* notFoundErrorString() const { return "The resource could not be found."; }
167  virtual const char* connectionRefusedString() const { return "The connection was refused by the listener at the other end of the connection."; }
168  virtual const char* unknownErrorString() const { return "Unknown error."; }
169 
171 };
172 
173 
174 } // namespace ecl
175 
176 #endif /* ECL_ERRORS_HANDLERS_HPP_ */
virtual const char * closeErrorString() const
Definition: handlers.hpp:145
virtual const char * configurationErrorString() const
Definition: handlers.hpp:147
virtual const char * notSupportedErrorString() const
Definition: handlers.hpp:157
virtual const char * constructorErrorString() const
Definition: handlers.hpp:141
virtual const char * busyErrorString() const
Definition: handlers.hpp:158
Error(const ErrorFlag &flag=UnknownError)
Configure the return type with an error flag.
Definition: handlers.hpp:65
virtual ErrorFlag flag() const
The flag identifying the error identified with this error handler.
Definition: handlers.hpp:72
ErrorFlag error_flag
Definition: handlers.hpp:170
virtual const char * readErrorString() const
Definition: handlers.hpp:149
virtual const char * isLockedErrorString() const
Definition: handlers.hpp:164
virtual const char * raiiErrorString() const
Definition: handlers.hpp:155
ErrorFlag
Enumerated flags for error message handling.
Definition: flags.hpp:36
virtual const char * notInitialisedErrorString() const
Definition: handlers.hpp:151
virtual const char * blockingErrorString() const
Definition: handlers.hpp:161
virtual const char * systemFailureErrorString() const
Definition: handlers.hpp:162
virtual void print(const char *loc)
Print a location dependent message to standard out.
Definition: handlers.hpp:94
virtual const char * writeErrorString() const
Definition: handlers.hpp:150
virtual const char * invalidArgErrorString() const
Definition: handlers.hpp:146
virtual const char * memoryErrorString() const
Definition: handlers.hpp:153
virtual const char * noErrorString() const
Definition: handlers.hpp:139
The primary error handler for ecl libraries.
Definition: handlers.hpp:58
virtual const char * unknownErrorString() const
Definition: handlers.hpp:168
virtual ~Error()
Definition: handlers.hpp:66
virtual const char * conversionErrorString() const
Definition: handlers.hpp:143
virtual const char * connectErrorString() const
Definition: handlers.hpp:148
virtual const char * notFoundErrorString() const
Definition: handlers.hpp:166
virtual const char * permissionsErrorString() const
Definition: handlers.hpp:152
virtual const char * outOfRangeErrorString() const
Definition: handlers.hpp:140
#define ecl_errors_PUBLIC
Definition: macros.hpp:37
virtual const char * isTimeOutErrorString() const
Definition: handlers.hpp:165
virtual const char * argNotSupportedErrorString() const
Definition: handlers.hpp:156
virtual const char * destructorErrorString() const
Definition: handlers.hpp:142
virtual const char * invalidObjectErrorString() const
Definition: handlers.hpp:163
Flags for error types.
virtual const char * interruptedErrorString() const
Definition: handlers.hpp:160
virtual const char * connectionRefusedString() const
Definition: handlers.hpp:167
virtual const char * outOfResourcesErrorString() const
Definition: handlers.hpp:159
virtual const char * usageErrorString() const
Definition: handlers.hpp:154
virtual void operator=(const ErrorFlag &error)
Definition: handlers.hpp:73
virtual const char * openErrorString() const
Definition: handlers.hpp:144
virtual const char * what() const
A simple string verbosely representing the error that is handled.
Definition: handlers.hpp:103


ecl_errors
Author(s): Daniel Stonier
autogenerated on Mon Feb 28 2022 22:16:11