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-2013 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 "OgreString.h"
34 #include <exception>
35 #include "OgreHeaderPrefix.h"
36 
37 // Check for OGRE assert mode
38 
39 // RELEASE_EXCEPTIONS mode
40 #if OGRE_ASSERT_MODE == 1
41 # if OGRE_DEBUG_MODE
42 # define OgreAssert( a, b ) assert( (a) && (b) )
43 # else
44 # if OGRE_COMP != OGRE_COMPILER_BORL
45 # define OgreAssert( a, b ) if( !(a) ) OGRE_EXCEPT( Ogre::Exception::ERR_RT_ASSERTION_FAILED, (b), "no function info")
46 # else
47 # define OgreAssert( a, b ) if( !(a) ) OGRE_EXCEPT( Ogre::Exception::ERR_RT_ASSERTION_FAILED, (b), __FUNC__ )
48 # endif
49 # endif
50 
51 // EXCEPTIONS mode
52 #elif OGRE_ASSERT_MODE == 2
53 # if OGRE_COMP != OGRE_COMPILER_BORL
54 # define OgreAssert( a, b ) if( !(a) ) OGRE_EXCEPT( Ogre::Exception::ERR_RT_ASSERTION_FAILED, (b), "no function info")
55 # else
56 # define OgreAssert( a, b ) if( !(a) ) OGRE_EXCEPT( Ogre::Exception::ERR_RT_ASSERTION_FAILED, (b), __FUNC__ )
57 # endif
58 
59 // STANDARD mode
60 #else
61 # define OgreAssert( a, b ) assert( (a) && (b) )
62 #endif
63 
64 namespace Ogre {
84  class _OgreExport Exception : public std::exception
85  {
86  protected:
87  long line;
88  int number;
93  mutable String fullDesc;
94  public:
110  ERR_NOT_IMPLEMENTED
111  };
112 
115  Exception( int number, const String& description, const String& source );
116 
119  Exception( int number, const String& description, const String& source, const char* type, const char* file, long line );
120 
123  Exception(const Exception& rhs);
124 
126  ~Exception() throw() {}
127 
130  void operator = (const Exception& rhs);
131 
142  virtual const String& getFullDescription(void) const;
143 
146  virtual int getNumber(void) const throw();
147 
150  virtual const String &getSource() const { return source; }
151 
154  virtual const String &getFile() const { return file; }
155 
158  virtual long getLine() const { return line; }
159 
164  virtual const String &getDescription(void) const { return description; }
165 
167  const char* what() const throw() { return getFullDescription().c_str(); }
168 
169  };
170 
171 
178  template <int num>
180  {
181  enum { number = num };
182  };
183 
184  // Specialised exceptions allowing each to be caught specifically
185  // backwards-compatible since exception codes still used
186 
188  {
189  public:
190  UnimplementedException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
191  : Exception(inNumber, inDescription, inSource, "UnimplementedException", inFile, inLine) {}
192  };
194  {
195  public:
196  FileNotFoundException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
197  : Exception(inNumber, inDescription, inSource, "FileNotFoundException", inFile, inLine) {}
198  };
200  {
201  public:
202  IOException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
203  : Exception(inNumber, inDescription, inSource, "IOException", inFile, inLine) {}
204  };
206  {
207  public:
208  InvalidStateException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
209  : Exception(inNumber, inDescription, inSource, "InvalidStateException", inFile, inLine) {}
210  };
212  {
213  public:
214  InvalidParametersException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
215  : Exception(inNumber, inDescription, inSource, "InvalidParametersException", inFile, inLine) {}
216  };
218  {
219  public:
220  ItemIdentityException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
221  : Exception(inNumber, inDescription, inSource, "ItemIdentityException", inFile, inLine) {}
222  };
224  {
225  public:
226  InternalErrorException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
227  : Exception(inNumber, inDescription, inSource, "InternalErrorException", inFile, inLine) {}
228  };
230  {
231  public:
232  RenderingAPIException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
233  : Exception(inNumber, inDescription, inSource, "RenderingAPIException", inFile, inLine) {}
234  };
236  {
237  public:
238  RuntimeAssertionException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
239  : Exception(inNumber, inDescription, inSource, "RuntimeAssertionException", inFile, inLine) {}
240  };
241 
242 
253  {
254  private:
257  public:
260  const String& desc,
261  const String& src, const char* file, long line)
262  {
263  return UnimplementedException(code.number, desc, src, file, line);
264  }
267  const String& desc,
268  const String& src, const char* file, long line)
269  {
270  return FileNotFoundException(code.number, desc, src, file, line);
271  }
274  const String& desc,
275  const String& src, const char* file, long line)
276  {
277  return IOException(code.number, desc, src, file, line);
278  }
281  const String& desc,
282  const String& src, const char* file, long line)
283  {
284  return InvalidStateException(code.number, desc, src, file, line);
285  }
288  const String& desc,
289  const String& src, const char* file, long line)
290  {
291  return InvalidParametersException(code.number, desc, src, file, line);
292  }
295  const String& desc,
296  const String& src, const char* file, long line)
297  {
298  return ItemIdentityException(code.number, desc, src, file, line);
299  }
302  const String& desc,
303  const String& src, const char* file, long line)
304  {
305  return ItemIdentityException(code.number, desc, src, file, line);
306  }
309  const String& desc,
310  const String& src, const char* file, long line)
311  {
312  return InternalErrorException(code.number, desc, src, file, line);
313  }
316  const String& desc,
317  const String& src, const char* file, long line)
318  {
319  return RenderingAPIException(code.number, desc, src, file, line);
320  }
323  const String& desc,
324  const String& src, const char* file, long line)
325  {
326  return RuntimeAssertionException(code.number, desc, src, file, line);
327  }
328 
329  };
330 
331 
332 
333 #ifndef OGRE_EXCEPT
334 #define OGRE_EXCEPT(num, desc, src) throw Ogre::ExceptionFactory::create( \
335  Ogre::ExceptionCodeType<num>(), desc, src, __FILE__, __LINE__ );
336 #endif
337 
340 } // Namespace Ogre
341 
342 #include "OgreHeaderSuffix.h"
343 
344 #endif
const char * what() const
Override std::exception::what.
static RuntimeAssertionException create(ExceptionCodeType< Exception::ERR_RT_ASSERTION_FAILED > code, const String &desc, const String &src, const char *file, long line)
static ItemIdentityException create(ExceptionCodeType< Exception::ERR_ITEM_NOT_FOUND > code, const String &desc, const String &src, const char *file, long line)
virtual const String & getFile() const
Gets source file name.
#define _OgreExport
Definition: OgrePlatform.h:257
~Exception()
Needed for compatibility with std::exception.
static FileNotFoundException create(ExceptionCodeType< Exception::ERR_FILE_NOT_FOUND > code, const String &desc, const String &src, const char *file, long line)
static RenderingAPIException create(ExceptionCodeType< Exception::ERR_RENDERINGAPI_ERROR > code, const String &desc, const String &src, const char *file, long line)
RenderingAPIException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
static InvalidParametersException create(ExceptionCodeType< Exception::ERR_INVALIDPARAMS > code, const String &desc, const String &src, const char *file, long line)
virtual const String & getDescription(void) const
Returns a string with only the &#39;description&#39; field of this exception.
Class implementing dispatch methods in order to construct by-value exceptions of a derived type based...
When thrown, provides information about an error that has occurred inside the engine.
Definition: OgreException.h:84
InternalErrorException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
UnimplementedException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
static ItemIdentityException create(ExceptionCodeType< Exception::ERR_DUPLICATE_ITEM > code, const String &desc, const String &src, const char *file, long line)
_StringBase String
virtual const String & getSource() const
Gets the source function.
ExceptionFactory()
Private constructor, no construction.
InvalidStateException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
IOException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
ExceptionCodes
Static definitions of error codes.
static IOException create(ExceptionCodeType< Exception::ERR_CANNOT_WRITE_TO_FILE > code, const String &desc, const String &src, const char *file, long line)
virtual long getLine() const
Gets line number.
static InvalidStateException create(ExceptionCodeType< Exception::ERR_INVALID_STATE > code, const String &desc, const String &src, const char *file, long line)
ItemIdentityException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
RuntimeAssertionException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
static UnimplementedException create(ExceptionCodeType< Exception::ERR_NOT_IMPLEMENTED > code, const String &desc, const String &src, const char *file, long line)
Template struct which creates a distinct type for each exception code.
InvalidParametersException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
FileNotFoundException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
static InternalErrorException create(ExceptionCodeType< Exception::ERR_INTERNAL_ERROR > code, const String &desc, const String &src, const char *file, long line)

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.