Go to the documentation of this file.00001
00008
00009
00010
00011
00012 #ifndef ECL_ERRORS_HANDLERS_HPP_
00013 #define ECL_ERRORS_HANDLERS_HPP_
00014
00015
00016
00017
00018
00019 #include <ecl/config/macros.hpp>
00020 #include <cstring>
00021 #include <cstdio>
00022 #include "macros.hpp"
00023 #include "flags.hpp"
00024
00025
00026
00027
00028
00029 namespace ecl {
00030
00058 class ecl_errors_PUBLIC Error {
00059 public:
00065 Error(const ErrorFlag& flag = UnknownError) : error_flag(flag) {}
00066
00071 virtual ErrorFlag flag() const { return error_flag; }
00072 virtual void operator=(const ErrorFlag &error) { error_flag = error; }
00073
00074
00075
00076
00077
00078
00079
00093 virtual void print(const char* loc) {
00094 printf("%s - %s\n",loc,what());
00095 }
00096
00102 virtual const char* what() const {
00103 switch (error_flag) {
00104 case (NoError) : { return noErrorString(); }
00105 case (OutOfRangeError) : { return outOfRangeErrorString(); }
00106 case (ConstructorError) : { return constructorErrorString(); }
00107 case (DestructorError) : { return destructorErrorString(); }
00108 case (ConversionError) : { return conversionErrorString(); }
00109 case (OpenError) : { return openErrorString(); }
00110 case (CloseError) : { return closeErrorString(); }
00111 case (InvalidArgError) : { return invalidArgErrorString(); }
00112 case (ConfigurationError) : { return configurationErrorString(); }
00113 case (ConnectionError) : { return connectErrorString(); }
00114 case (ReadError) : { return readErrorString(); }
00115 case (WriteError) : { return writeErrorString(); }
00116 case (NotInitialisedError) : { return notInitialisedErrorString(); }
00117 case (PermissionsError) : { return permissionsErrorString(); }
00118 case (MemoryError) : { return memoryErrorString(); }
00119 case (UsageError) : { return usageErrorString(); }
00120 case (RaiiError) : { return raiiErrorString(); }
00121 case (ArgNotSupportedError) : { return argNotSupportedErrorString(); }
00122 case (NotSupportedError) : { return notSupportedErrorString(); }
00123 case (BusyError) : { return busyErrorString(); }
00124 case (OutOfResourcesError) : { return outOfResourcesErrorString(); }
00125 case (InterruptedError) : { return interruptedErrorString(); }
00126 case (BlockingError) : { return blockingErrorString(); }
00127 case (SystemFailureError) : { return systemFailureErrorString(); }
00128 case (InvalidObjectError) : { return invalidObjectErrorString(); }
00129 case (IsLockedError) : { return isLockedErrorString(); }
00130 case (TimeOutError) : { return isTimeOutErrorString(); }
00131 case (NotFoundError) : { return notFoundErrorString(); }
00132 case (ConnectionRefusedError) : { return connectionRefusedString(); }
00133
00134 default : { return unknownErrorString(); }
00135 }
00136 }
00137 protected:
00138 virtual const char* noErrorString() const { return "No error."; }
00139 virtual const char* outOfRangeErrorString() const { return "Out of range error - tried to access beyond the range of the object (usually container)."; }
00140 virtual const char* constructorErrorString() const { return "The constructor did not produce a valid object."; }
00141 virtual const char* destructorErrorString() const { return "The destructor failed to self destruct."; }
00142 virtual const char* conversionErrorString() const { return "Conversion from one type to another failed."; }
00143 virtual const char* openErrorString() const { return "Could not open the requested object."; }
00144 virtual const char* closeErrorString() const { return "Could not close the requested object."; }
00145 virtual const char* invalidArgErrorString() const { return "One of the supplied input arguments was invalid."; }
00146 virtual const char* configurationErrorString() const { return "There was a configuration error."; }
00147 virtual const char* connectErrorString() const { return "Could not connect."; }
00148 virtual const char* readErrorString() const { return "Could not read from the object."; }
00149 virtual const char* writeErrorString() const { return "Could not write to the object."; }
00150 virtual const char* notInitialisedErrorString() const { return "The object has not been properly initialised yet."; }
00151 virtual const char* permissionsErrorString() const { return "The caller does not have the required permissions."; }
00152 virtual const char* memoryErrorString() const { return "There was a problem allocating the requested memory."; }
00153 virtual const char* usageErrorString() const { return "The object was used incorrectly."; }
00154 virtual const char* raiiErrorString() const { return "The object is pure RAII style and must be initialised correctly, you may not use the default constructor."; }
00155 virtual const char* argNotSupportedErrorString() const { return "The combination of input arguments is not supported on this platform."; }
00156 virtual const char* notSupportedErrorString() const { return "This operation is not supported on this platform."; }
00157 virtual const char* busyErrorString() const { return "Resources are busy, operation is not permitted"; }
00158 virtual const char* outOfResourcesErrorString() const { return "Out of resources, cannot proceed."; }
00159 virtual const char* interruptedErrorString() const { return "This operation was interrupted."; }
00160 virtual const char* blockingErrorString() const { return "A device marked as blocking, but used as non-blocking, or vice versa."; }
00161 virtual const char* systemFailureErrorString() const { return "A subsystem has failed mid operation."; }
00162 virtual const char* invalidObjectErrorString() const { return "Attempted to work on an invalid object."; }
00163 virtual const char* isLockedErrorString() const { return "Invalidates attempts to work further because an object is locked."; }
00164 virtual const char* isTimeOutErrorString() const { return "A timeout occured."; }
00165 virtual const char* notFoundErrorString() const { return "The resource could not be found."; }
00166 virtual const char* connectionRefusedString() const { return "The connection was refused by the listener at the other end of the connection."; }
00167 virtual const char* unknownErrorString() const { return "Unknown error."; }
00168
00169 ErrorFlag error_flag;
00170 };
00171
00172
00173 }
00174
00175 #endif