openModeller  Version 1.5.0
Exceptions.hh
Go to the documentation of this file.
1 #ifndef _EXCEPTIONS_HH
2 #define _EXCEPTIONS_HH
3 
4 // Microsoft VC8 requires <string> before <stdexcept> in order for
5 // this code to compile.
6 #include <string>
7 #include <stdexcept>
8 
9 //
10 // The class OmException is the base
11 // class for all non-stdlib exceptions
12 // generated by the OpenModeller library.
13 //
14 class OmException : public std::runtime_error {
15 public:
16  OmException( const std::string& msg ) :
17  std::runtime_error( msg )
18  {}
19 
20 };
21 
22 //
23 // Tag all exceptions from the configuration
24 // functionality with this.
25 //
27 public:
28  ConfigurationException( const std::string& msg ) :
29  OmException( msg )
30  {}
31 };
32 
34 public:
35  AttributeNotFound( const std::string& attrName ) :
36  ConfigurationException( "XML attribute " + attrName + " not found"),
37  attrName( attrName )
38  {}
39  ~AttributeNotFound() throw() {}
40  const std::string& getName() const {
41  return attrName;
42  }
43 private:
44  std::string attrName;
45 };
46 
48 public:
49  SubsectionNotFound( const std::string& sectionName ) :
50  ConfigurationException( "XML subsection " + sectionName + " not found"),
51  sectionName( sectionName )
52  {}
53  ~SubsectionNotFound() throw() {}
54  const std::string& getName() const {
55  return sectionName;
56  }
57 private:
58  std::string sectionName;
59 };
60 
62 public:
63  InvalidType( const std::string& msg ) :
65  {}
66 };
67 
69 public:
70  XmlParseException( const std::string& msg ) :
72  {}
73 };
74 
75 //
76 // Simple IO Exception -- thrown for any File IO problem.
77 //
78 class FileIOException : public OmException {
79 public:
80  FileIOException( const std::string& msg, const std::string& filename ) :
81  OmException( msg ),
82  filename( filename )
83  {}
84  ~FileIOException() throw() {}
85  std::string getFilename() {
86  return filename;
87  }
88 private:
89  std::string filename;
90 };
91 
92 //
93 // General memory exception
94 class MemoryException : public OmException {
95 public:
96  MemoryException( const std::string& msg ) :
97  OmException( msg )
98  {}
99 };
100 
101 //
102 // Invalid Parameter Exception -- thrown in the library when an
103 // a parameter value is invalid
104 //
106 public:
107  InvalidParameterException( const std::string& msg ) :
108  OmException( msg )
109  {}
110 };
111 
112 //
113 // Invalid Sampling Configuration Exception -- thrown when clients try
114 // to get a pseudo absence sample without specifying the Environment
115 // object
117 public:
118  SamplerException( const std::string& msg ) :
119  OmException( msg )
120  {}
121 };
122 
123 //
124 // AlgorithmException -- thrown in the library when an
125 // algorithm cannot execute correctly.
126 //
128 public:
129  AlgorithmException( const std::string& msg ) :
130  OmException( msg )
131  {}
132 };
133 
134 //
135 // RasterException -- thrown in the library when
136 // there is an issue with a raster.
137 //
138 class RasterException : public OmException {
139 public:
140  RasterException( const std::string& msg, int code=0 ) :
141  OmException( msg ),
142  code( code )
143  {}
144  ~RasterException() throw() {}
145  int getCode() {
146  return code;
147  }
148 private:
149  // 1= ongoing concurrent download of remote raster
150  int code;
151 };
152 
153 //
154 // OccurrencesReaderException -- thrown in the library when
155 // there is an issue when reading occurrences data.
156 //
158 public:
159  OccurrencesReaderException( const std::string& msg ) :
160  OmException( msg )
161  {}
162 };
163 
164 #endif
InvalidParameterException(const std::string &msg)
Definition: Exceptions.hh:107
InvalidType(const std::string &msg)
Definition: Exceptions.hh:63
std::string attrName
Definition: Exceptions.hh:44
const std::string & getName() const
Definition: Exceptions.hh:40
const std::string & getName() const
Definition: Exceptions.hh:54
std::string filename
Definition: Exceptions.hh:89
FileIOException(const std::string &msg, const std::string &filename)
Definition: Exceptions.hh:80
OmException(const std::string &msg)
Definition: Exceptions.hh:16
SubsectionNotFound(const std::string &sectionName)
Definition: Exceptions.hh:49
ConfigurationException(const std::string &msg)
Definition: Exceptions.hh:28
std::string getFilename()
Definition: Exceptions.hh:85
OccurrencesReaderException(const std::string &msg)
Definition: Exceptions.hh:159
SamplerException(const std::string &msg)
Definition: Exceptions.hh:118
RasterException(const std::string &msg, int code=0)
Definition: Exceptions.hh:140
AttributeNotFound(const std::string &attrName)
Definition: Exceptions.hh:35
AlgorithmException(const std::string &msg)
Definition: Exceptions.hh:129
XmlParseException(const std::string &msg)
Definition: Exceptions.hh:70
std::string sectionName
Definition: Exceptions.hh:58
MemoryException(const std::string &msg)
Definition: Exceptions.hh:96