OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreException.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4 (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2014 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef __Exception_H_
29 #define __Exception_H_
30 
31 // Precompiler options
32 #include "OgrePrerequisites.h"
33 #include <exception>
34 #include "OgreHeaderPrefix.h"
35 
36 // Check for OGRE assert mode
37 
38 // RELEASE_EXCEPTIONS mode
39 #if OGRE_ASSERT_MODE == 1
40 # if OGRE_DEBUG_MODE
41 # define OgreAssert( a, b ) assert( (a) && (b) )
42 # else
43 # if OGRE_COMP != OGRE_COMPILER_BORL
44 # define OgreAssert( a, b ) if( !(a) ) OGRE_EXCEPT( Ogre::Exception::ERR_RT_ASSERTION_FAILED, (b), "no function info")
45 # else
46 # define OgreAssert( a, b ) if( !(a) ) OGRE_EXCEPT( Ogre::Exception::ERR_RT_ASSERTION_FAILED, (b), __FUNC__ )
47 # endif
48 # endif
49 
50 // EXCEPTIONS mode
51 #elif OGRE_ASSERT_MODE == 2
52 # if OGRE_COMP != OGRE_COMPILER_BORL
53 # define OgreAssert( a, b ) if( !(a) ) OGRE_EXCEPT( Ogre::Exception::ERR_RT_ASSERTION_FAILED, (b), "no function info")
54 # else
55 # define OgreAssert( a, b ) if( !(a) ) OGRE_EXCEPT( Ogre::Exception::ERR_RT_ASSERTION_FAILED, (b), __FUNC__ )
56 # endif
57 
58 // STANDARD mode
59 #else
60 # define OgreAssert( a, b ) assert( (a) && (b) )
61 #endif
62 
63 namespace Ogre {
64  typedef _StringBase String;
65 
85  class _OgreExport Exception : public std::exception
86  {
87  protected:
88  long line;
89  int number;
94  mutable String fullDesc;
95  public:
111  ERR_NOT_IMPLEMENTED
112  };
113 
116  Exception( int number, const String& description, const String& source );
117 
120  Exception( int number, const String& description, const String& source, const char* type, const char* file, long line );
121 
124  Exception(const Exception& rhs);
125 
127  ~Exception() throw() {}
128 
131  Exception & operator = (const Exception& rhs);
132 
143  virtual const String& getFullDescription(void) const;
144 
147  virtual int getNumber(void) const throw();
148 
151  virtual const String &getSource() const { return source; }
152 
155  virtual const String &getFile() const { return file; }
156 
159  virtual long getLine() const { return line; }
160 
165  virtual const String &getDescription(void) const { return description; }
166 
168  const char* what() const throw() { return getFullDescription().c_str(); }
169 
170  };
171 
172 
179  template <int num>
181  {
182  enum { number = num };
183  };
184 
185  // Specialised exceptions allowing each to be caught specifically
186  // backwards-compatible since exception codes still used
187 
189  {
190  public:
191  UnimplementedException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
192  : Exception(inNumber, inDescription, inSource, "UnimplementedException", inFile, inLine) {}
193  };
195  {
196  public:
197  FileNotFoundException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
198  : Exception(inNumber, inDescription, inSource, "FileNotFoundException", inFile, inLine) {}
199  };
201  {
202  public:
203  IOException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
204  : Exception(inNumber, inDescription, inSource, "IOException", inFile, inLine) {}
205  };
207  {
208  public:
209  InvalidStateException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
210  : Exception(inNumber, inDescription, inSource, "InvalidStateException", inFile, inLine) {}
211  };
213  {
214  public:
215  InvalidParametersException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
216  : Exception(inNumber, inDescription, inSource, "InvalidParametersException", inFile, inLine) {}
217  };
219  {
220  public:
221  ItemIdentityException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
222  : Exception(inNumber, inDescription, inSource, "ItemIdentityException", inFile, inLine) {}
223  };
225  {
226  public:
227  InternalErrorException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
228  : Exception(inNumber, inDescription, inSource, "InternalErrorException", inFile, inLine) {}
229  };
231  {
232  public:
233  RenderingAPIException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
234  : Exception(inNumber, inDescription, inSource, "RenderingAPIException", inFile, inLine) {}
235  };
237  {
238  public:
239  RuntimeAssertionException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
240  : Exception(inNumber, inDescription, inSource, "RuntimeAssertionException", inFile, inLine) {}
241  };
242 
243 
254  {
255  private:
258  public:
261  const String& desc,
262  const String& src, const char* file, long line)
263  {
264  return UnimplementedException(Exception::ERR_NOT_IMPLEMENTED, desc, src, file, line);
265  }
268  const String& desc,
269  const String& src, const char* file, long line)
270  {
271  return FileNotFoundException(Exception::ERR_FILE_NOT_FOUND, desc, src, file, line);
272  }
275  const String& desc,
276  const String& src, const char* file, long line)
277  {
278  return IOException(Exception::ERR_CANNOT_WRITE_TO_FILE, desc, src, file, line);
279  }
282  const String& desc,
283  const String& src, const char* file, long line)
284  {
285  return InvalidStateException(Exception::ERR_INVALID_STATE, desc, src, file, line);
286  }
289  const String& desc,
290  const String& src, const char* file, long line)
291  {
292  return InvalidParametersException(Exception::ERR_INVALIDPARAMS, desc, src, file, line);
293  }
296  const String& desc,
297  const String& src, const char* file, long line)
298  {
299  return ItemIdentityException(Exception::ERR_ITEM_NOT_FOUND, desc, src, file, line);
300  }
303  const String& desc,
304  const String& src, const char* file, long line)
305  {
306  return ItemIdentityException(Exception::ERR_DUPLICATE_ITEM, desc, src, file, line);
307  }
310  const String& desc,
311  const String& src, const char* file, long line)
312  {
313  return InternalErrorException(Exception::ERR_INTERNAL_ERROR, desc, src, file, line);
314  }
317  const String& desc,
318  const String& src, const char* file, long line)
319  {
320  return RenderingAPIException(Exception::ERR_RENDERINGAPI_ERROR, desc, src, file, line);
321  }
324  const String& desc,
325  const String& src, const char* file, long line)
326  {
327  return RuntimeAssertionException(Exception::ERR_RT_ASSERTION_FAILED, desc, src, file, line);
328  }
329 
330  };
331 
332 
333 
334 #ifndef OGRE_EXCEPT
335 #define OGRE_EXCEPT(num, desc, src) throw Ogre::ExceptionFactory::create( \
336  Ogre::ExceptionCodeType<num>(), desc, src, __FILE__, __LINE__ );
337 #endif
338 
341 } // Namespace Ogre
342 
343 #include "OgreHeaderSuffix.h"
344 
345 #endif
IOException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
#define _OgreExport
Definition: OgrePlatform.h:255
UnimplementedException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
std::string _StringBase
ItemIdentityException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
InvalidStateException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
RenderingAPIException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
const char * what() const
Override std::exception::what.
virtual const String & getDescription(void) const
Returns a string with only the 'description' field of this exception.
RuntimeAssertionException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
static ItemIdentityException create(ExceptionCodeType< Exception::ERR_ITEM_NOT_FOUND >, const String &desc, const String &src, const char *file, long line)
static InvalidStateException create(ExceptionCodeType< Exception::ERR_INVALID_STATE >, const String &desc, const String &src, const char *file, long line)
static UnimplementedException create(ExceptionCodeType< Exception::ERR_NOT_IMPLEMENTED >, const String &desc, const String &src, const char *file, long line)
static IOException create(ExceptionCodeType< Exception::ERR_CANNOT_WRITE_TO_FILE >, const String &desc, const String &src, const char *file, long line)
static InvalidParametersException create(ExceptionCodeType< Exception::ERR_INVALIDPARAMS >, const String &desc, const String &src, const char *file, long line)
static FileNotFoundException create(ExceptionCodeType< Exception::ERR_FILE_NOT_FOUND >, const String &desc, const String &src, const char *file, long line)
static InternalErrorException create(ExceptionCodeType< Exception::ERR_INTERNAL_ERROR >, const String &desc, const String &src, const char *file, long line)
virtual long getLine() const
Gets line number.
ExceptionFactory()
Private constructor, no construction.
static RenderingAPIException create(ExceptionCodeType< Exception::ERR_RENDERINGAPI_ERROR >, const String &desc, const String &src, const char *file, long line)
virtual const String & getFile() const
Gets source file name.
static ItemIdentityException create(ExceptionCodeType< Exception::ERR_DUPLICATE_ITEM >, const String &desc, const String &src, const char *file, long line)
Class implementing dispatch methods in order to construct by-value exceptions of a derived type based...
static RuntimeAssertionException create(ExceptionCodeType< Exception::ERR_RT_ASSERTION_FAILED >, const String &desc, const String &src, const char *file, long line)
InternalErrorException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
Template struct which creates a distinct type for each exception code.
FileNotFoundException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
_StringBase String
Definition: OgreCommon.h:53
~Exception()
Needed for compatibility with std::exception.
ExceptionCodes
Static definitions of error codes.
When thrown, provides information about an error that has occurred inside the engine.
Definition: OgreException.h:85
InvalidParametersException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)