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 
58 class ecl_errors_PUBLIC Error {
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 
170  ErrorFlag error_flag;
171 };
172 
173 
174 } // namespace ecl
175 
176 #endif /* ECL_ERRORS_HANDLERS_HPP_ */
ecl::NotInitialisedError
@ NotInitialisedError
Definition: flags.hpp:64
ecl::OpenError
@ OpenError
Definition: flags.hpp:57
ecl::ConnectionError
@ ConnectionError
Definition: flags.hpp:61
ecl::WriteError
@ WriteError
Definition: flags.hpp:63
ecl::NotFoundError
@ NotFoundError
Definition: flags.hpp:79
ecl::ErrorFlag
ErrorFlag
Enumerated flags for error message handling.
Definition: flags.hpp:42
ecl::BusyError
@ BusyError
Definition: flags.hpp:71
ecl::UsageError
@ UsageError
Definition: flags.hpp:67
ecl::IsLockedError
@ IsLockedError
Definition: flags.hpp:77
ecl::OutOfResourcesError
@ OutOfResourcesError
Definition: flags.hpp:72
flags.hpp
Flags for error types.
ecl::SystemFailureError
@ SystemFailureError
Definition: flags.hpp:75
ecl::MemoryError
@ MemoryError
Definition: flags.hpp:66
ecl::TimeOutError
@ TimeOutError
Definition: flags.hpp:78
ecl::ConnectionRefusedError
@ ConnectionRefusedError
Definition: flags.hpp:80
macros.hpp
Macros for error-checking and program termination.
ecl::DestructorError
@ DestructorError
Definition: flags.hpp:55
ecl::ArgNotSupportedError
@ ArgNotSupportedError
Definition: flags.hpp:69
ecl::RaiiError
@ RaiiError
Definition: flags.hpp:68
ecl::ConstructorError
@ ConstructorError
Definition: flags.hpp:54
ecl::InterruptedError
@ InterruptedError
Definition: flags.hpp:73
ecl_errors_PUBLIC
#define ecl_errors_PUBLIC
Definition: macros.hpp:37
ecl::NoError
@ NoError
Definition: flags.hpp:51
ecl::InvalidObjectError
@ InvalidObjectError
Definition: flags.hpp:76
ecl::InvalidArgError
@ InvalidArgError
Definition: flags.hpp:59
ecl::PermissionsError
@ PermissionsError
Definition: flags.hpp:65
ecl::UnknownError
@ UnknownError
Definition: flags.hpp:52
ecl::CloseError
@ CloseError
Definition: flags.hpp:58
ecl::ConversionError
@ ConversionError
Definition: flags.hpp:56
ecl::NotSupportedError
@ NotSupportedError
Definition: flags.hpp:70
macros.hpp
ecl::ReadError
@ ReadError
Definition: flags.hpp:62
ecl::OutOfRangeError
@ OutOfRangeError
Definition: flags.hpp:53
ecl::BlockingError
@ BlockingError
Definition: flags.hpp:74
ecl
ecl::ConfigurationError
@ ConfigurationError
Definition: flags.hpp:60


ecl_errors
Author(s): Daniel Stonier
autogenerated on Tue Jun 9 2020 03:25:03