00001 /* 00002 Copyright 2007 Erez Bibi (erezbibi@users.sourceforge.net) 00003 This file is part of Beesnest. 00004 00005 Beesnest is free software; you can redistribute it and/or modify 00006 it under the terms of the GNU General Public License as published by 00007 the Free Software Foundation; either version 2 of the License, or 00008 (at your option) any later version. 00009 00010 Beesnest is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 GNU General Public License for more details. 00014 00015 You should have received a copy of the GNU General Public License 00016 along with Beesnest; if not, write to the Free Software 00017 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00018 */ 00019 00020 /* DcException.h: interface for the CdcException class. */ 00021 00022 #ifndef __CDC_EXCEPTION 00023 #define __CDC_EXCEPTION 00024 00025 00026 /** Exceptions thrown in this program. */ 00027 enum t_exception_num 00028 { 00029 /** General exception. */ 00030 DC_GENERAL_EXP = 0, 00031 00032 /** General file exception. */ 00033 DC_FILE_EXP = 10, 00034 /** Server cannot find the requested file under its root directory. */ 00035 DC_FILE_NOT_FOUND_EXP, 00036 /** The system request a text/binary file in a binary/text format. */ 00037 DC_WRONG_FILE_TYPE_EXP, 00038 /** The format of the parameters file is wrong. */ 00039 DC_WRONG_FILE_FORMAT_EXP, 00040 00041 /** General parsing exception. */ 00042 DC_PARSE_EXP = 20, 00043 /** Cannot parse the request message. */ 00044 DC_CNT_PRS_REQ_EXP, 00045 /** Cannot parse the request line. */ 00046 DC_CNT_PRS_REQ_LINE_EXP, 00047 /** Cannot parse header line. */ 00048 DC_CNT_PRS_HEADER_EXP, 00049 /** Cannot parse query. */ 00050 DC_CNT_PRS_QUERY_EXP, 00051 /** Cannot parse chunk request. */ 00052 DC_CNT_PRS_CNK_EXP, 00053 /** Request method is not supported.*/ 00054 DC_NOT_SUPPORT 00055 }; 00056 00057 00058 #include "DcString.h" 00059 00060 00061 /** 00062 * CdcException is the base class for the exceptions class. The only virtual 00063 * functions is <b>Print</b> and </b>Act</b>. The default implementation of 00064 * Print prints a relevant message to <b>stderr</b>. The implementation of Act 00065 * is empty in this base class. Derived classes can preform some relevant action 00066 * for the kind of exception. It make sense to over write the constructors though. 00067 * <p> 00068 * @author Erez Bibi 00069 * @version 1.0 00070 */ 00071 class CdcException 00072 { 00073 protected: 00074 /** The code of this exception. */ 00075 int nCode; 00076 /** The message of this exception. */ 00077 CdcString sMessage; 00078 00079 public: 00080 /** 00081 * Constructor with error code, or default constructor. 00082 * <p> 00083 * @param code The error code for this exception (DC_GENERAL_EXP 00084 * is the default). 00085 */ 00086 CdcException (t_exception_num code = DC_GENERAL_EXP); 00087 00088 /** 00089 * Constructor with code and message, or just message. 00090 * <p> 00091 * @param msg The error message for this exception. 00092 * @param code The error code for this exception (DC_GENERAL_EXP 00093 * is the default). 00094 */ 00095 CdcException (const CdcString& msg, t_exception_num code = DC_GENERAL_EXP); 00096 00097 /** 00098 * Destructor - Does nothing. 00099 */ 00100 virtual ~CdcException(); 00101 00102 /** 00103 * This function is virtual function to get the exception message as a 00104 * string. The user does not has to over write this function, the base 00105 * behavior is good in most cases. 00106 */ 00107 virtual CdcString ToStr () const; 00108 00109 /** 00110 * This function can do some relevant action on this exception. 00111 * The implementation in this base class is empty. 00112 */ 00113 virtual void Act (); 00114 00115 /** 00116 * Return error code number. 00117 * <p> 00118 * @return (int) Error code. 00119 */ 00120 virtual int GetExpCode () const; 00121 00122 /** 00123 * Return a reference to the error message. 00124 * <p> 00125 * @return (CdcString) Error message. 00126 */ 00127 virtual CdcString GetExpMessage () const; 00128 00129 }; 00130 00131 #endif /* __CDC_EXCEPTION */