openModeller
Version 1.4.0
|
00001 #ifndef _EXCEPTIONS_HH 00002 #define _EXCEPTIONS_HH 00003 00004 // Microsoft VC8 requires <string> before <stdexcept> in order for 00005 // this code to compile. 00006 #include <string> 00007 #include <stdexcept> 00008 00009 // 00010 // The class OmException is the base 00011 // class for all non-stdlib exceptions 00012 // generated by the OpenModeller library. 00013 // 00014 class OmException : public std::runtime_error { 00015 public: 00016 OmException( const std::string& msg ) : 00017 std::runtime_error( msg ) 00018 {} 00019 00020 }; 00021 00022 // 00023 // Tag all exceptions from the configuration 00024 // functionality with this. 00025 // 00026 class ConfigurationException : public OmException { 00027 public: 00028 ConfigurationException( const std::string& msg ) : 00029 OmException( msg ) 00030 {} 00031 }; 00032 00033 class AttributeNotFound : public ConfigurationException { 00034 public: 00035 AttributeNotFound( const std::string& attrName ) : 00036 ConfigurationException( "XML attribute " + attrName + " not found"), 00037 attrName( attrName ) 00038 {} 00039 ~AttributeNotFound() throw() {} 00040 const std::string& getName() const { 00041 return attrName; 00042 } 00043 private: 00044 std::string attrName; 00045 }; 00046 00047 class SubsectionNotFound : public ConfigurationException { 00048 public: 00049 SubsectionNotFound( const std::string& sectionName ) : 00050 ConfigurationException( "XML subsection " + sectionName + " not found"), 00051 sectionName( sectionName ) 00052 {} 00053 ~SubsectionNotFound() throw() {} 00054 const std::string& getName() const { 00055 return sectionName; 00056 } 00057 private: 00058 std::string sectionName; 00059 }; 00060 00061 class InvalidType : public ConfigurationException { 00062 public: 00063 InvalidType( const std::string& msg ) : 00064 ConfigurationException( msg ) 00065 {} 00066 }; 00067 00068 class XmlParseException : public ConfigurationException { 00069 public: 00070 XmlParseException( const std::string& msg ) : 00071 ConfigurationException( msg ) 00072 {} 00073 }; 00074 00075 // 00076 // Simple IO Exception -- thrown for any File IO problem. 00077 // 00078 class FileIOException : public OmException { 00079 public: 00080 FileIOException( const std::string& msg, const std::string& filename ) : 00081 OmException( msg ), 00082 filename( filename ) 00083 {} 00084 ~FileIOException() throw() {} 00085 std::string getFilename() { 00086 return filename; 00087 } 00088 private: 00089 std::string filename; 00090 }; 00091 00092 // 00093 // General memory exception 00094 class MemoryException : public OmException { 00095 public: 00096 MemoryException( const std::string& msg ) : 00097 OmException( msg ) 00098 {} 00099 }; 00100 00101 // 00102 // Invalid Parameter Exception -- thrown in the library when an 00103 // a parameter value is invalid 00104 // 00105 class InvalidParameterException : public OmException { 00106 public: 00107 InvalidParameterException( const std::string& msg ) : 00108 OmException( msg ) 00109 {} 00110 }; 00111 00112 // 00113 // Invalid Sampling Configuration Exception -- thrown when clients try 00114 // to get a pseudo absence sample without specifying the Environment 00115 // object 00116 class SamplerException : public OmException { 00117 public: 00118 SamplerException( const std::string& msg ) : 00119 OmException( msg ) 00120 {} 00121 }; 00122 00123 // 00124 // AlgorithmException -- thrown in the library when an 00125 // algorithm cannot execute correctly. 00126 // 00127 class AlgorithmException : public OmException { 00128 public: 00129 AlgorithmException( const std::string& msg ) : 00130 OmException( msg ) 00131 {} 00132 }; 00133 00134 // 00135 // RasterException -- thrown in the library when 00136 // there is an issue with a raster. 00137 // 00138 class RasterException : public OmException { 00139 public: 00140 RasterException( const std::string& msg, int code=0 ) : 00141 OmException( msg ), 00142 code( code ) 00143 {} 00144 ~RasterException() throw() {} 00145 int getCode() { 00146 return code; 00147 } 00148 private: 00149 // 1= ongoing concurrent download of remote raster 00150 int code; 00151 }; 00152 00153 // 00154 // OccurrencesReaderException -- thrown in the library when 00155 // there is an issue when reading occurrences data. 00156 // 00157 class OccurrencesReaderException : public OmException { 00158 public: 00159 OccurrencesReaderException( const std::string& msg ) : 00160 OmException( msg ) 00161 {} 00162 }; 00163 00164 #endif