libftc
|
00001 00005 #ifndef FTC_EXCEPTION_H_ 00006 #define FTC_EXCEPTION_H_ 00007 00008 #include <string> 00009 #include <exception> 00010 00014 enum FtcErrorCode{ 00015 OK = 0, 00016 FILE_NOT_OPEN=249, 00017 MAX_CLIENTS_REACHED=250, 00018 FILE_LOCKED, 00019 NO_PERMISSION, 00020 FILE_NOT_FOUND, 00021 INVALID_KEY, 00022 FAILURE 00023 }; 00024 00028 class FtcException : public std::exception { 00029 public: 00036 FtcException( FtcErrorCode errcode, std::string const& msg) 00037 { 00038 code = errcode; 00039 m_msg = msg; 00040 } 00041 00045 virtual ~FtcException() throw() {} 00046 00052 char const* what() const throw() 00053 { 00054 return m_msg.c_str(); 00055 } 00056 00062 virtual FtcErrorCode erroCode(){ 00063 return code; 00064 } 00065 00066 protected: 00070 FtcErrorCode code; 00074 std::string m_msg; 00075 }; 00076 00081 class FileNotOpenException : public FtcException{ 00082 public: 00088 explicit FileNotOpenException( std::string msg ) 00089 : FtcException(FILE_NOT_OPEN,msg){} 00090 }; 00091 00096 class MaxClientsReachedException : public FtcException{ 00097 public: 00103 explicit MaxClientsReachedException( std::string msg ) 00104 : FtcException(MAX_CLIENTS_REACHED,msg){} 00105 }; 00106 00111 class FileLockedException: public FtcException{ 00112 public: 00118 explicit FileLockedException( std::string msg ) 00119 : FtcException(FILE_LOCKED,msg){} 00120 }; 00121 00126 class NoPermissionException: public FtcException{ 00127 public: 00133 explicit NoPermissionException( std::string msg ) 00134 : FtcException(NO_PERMISSION,msg){} 00135 }; 00136 00141 class FileNotFoundException : public FtcException{ 00142 public: 00148 explicit FileNotFoundException( std::string msg ) 00149 : FtcException(FILE_NOT_FOUND,msg) {} 00150 }; 00151 00156 class InvalidKeyException: public FtcException{ 00157 public: 00163 explicit InvalidKeyException( std::string msg ) 00164 : FtcException(INVALID_KEY,msg){} 00165 }; 00166 00170 class FailureException: public FtcException{ 00171 public: 00177 explicit FailureException( std::string msg ) 00178 : FtcException(FAILURE,msg){} 00179 }; 00180 00181 #endif 00182