OGRE  1.9
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 "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 
172  // Specialised exceptions allowing each to be caught specifically
173  // backwards-compatible since exception codes still used
174 
176  {
177  public:
178  UnimplementedException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
179  : Exception(inNumber, inDescription, inSource, "UnimplementedException", inFile, inLine) {}
180  };
182  {
183  public:
184  FileNotFoundException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
185  : Exception(inNumber, inDescription, inSource, "FileNotFoundException", inFile, inLine) {}
186  };
188  {
189  public:
190  IOException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
191  : Exception(inNumber, inDescription, inSource, "IOException", inFile, inLine) {}
192  };
194  {
195  public:
196  InvalidStateException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
197  : Exception(inNumber, inDescription, inSource, "InvalidStateException", inFile, inLine) {}
198  };
200  {
201  public:
202  InvalidParametersException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
203  : Exception(inNumber, inDescription, inSource, "InvalidParametersException", inFile, inLine) {}
204  };
206  {
207  public:
208  ItemIdentityException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
209  : Exception(inNumber, inDescription, inSource, "ItemIdentityException", inFile, inLine) {}
210  };
212  {
213  public:
214  InternalErrorException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
215  : Exception(inNumber, inDescription, inSource, "InternalErrorException", inFile, inLine) {}
216  };
218  {
219  public:
220  RenderingAPIException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
221  : Exception(inNumber, inDescription, inSource, "RenderingAPIException", inFile, inLine) {}
222  };
224  {
225  public:
226  RuntimeAssertionException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
227  : Exception(inNumber, inDescription, inSource, "RuntimeAssertionException", inFile, inLine) {}
228  };
229 
230 
235  {
236  private:
239  public:
241  Exception::ExceptionCodes code, int number,
242  const String& desc,
243  const String& src, const char* file, long line)
244  {
245  switch (code)
246  {
247  case Exception::ERR_CANNOT_WRITE_TO_FILE: throw IOException(number, desc, src, file, line);
248  case Exception::ERR_INVALID_STATE: throw InvalidStateException(number, desc, src, file, line);
249  case Exception::ERR_INVALIDPARAMS: throw InvalidParametersException(number, desc, src, file, line);
250  case Exception::ERR_RENDERINGAPI_ERROR: throw RenderingAPIException(number, desc, src, file, line);
251  case Exception::ERR_DUPLICATE_ITEM: throw ItemIdentityException(number, desc, src, file, line);
252  case Exception::ERR_ITEM_NOT_FOUND: throw ItemIdentityException(number, desc, src, file, line);
253  case Exception::ERR_FILE_NOT_FOUND: throw FileNotFoundException(number, desc, src, file, line);
254  case Exception::ERR_INTERNAL_ERROR: throw InternalErrorException(number, desc, src, file, line);
255  case Exception::ERR_RT_ASSERTION_FAILED: throw RuntimeAssertionException(number, desc, src, file, line);
256  case Exception::ERR_NOT_IMPLEMENTED: throw UnimplementedException(number, desc, src, file, line);
257  default: throw Exception(number, desc, src, "Exception", file, line);
258  }
259  }
260  };
261 
262 
263 
264 #ifndef OGRE_EXCEPT
265 #define OGRE_EXCEPT(code, desc, src) Ogre::ExceptionFactory::throwException(code, code, desc, src, __FILE__, __LINE__);
266 #define OGRE_EXCEPT_EX(code, num, desc, src) Ogre::ExceptionFactory::throwException(code, num, desc, src, __FILE__, __LINE__);
267 #else
268 #define OGRE_EXCEPT_EX(code, num, desc, src) OGRE_EXCEPT(code, desc, src);
269 #endif
270 
273 } // Namespace Ogre
274 
275 #include "OgreHeaderSuffix.h"
276 
277 #endif
IOException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
#define _OgreExport
Definition: OgrePlatform.h:260
UnimplementedException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
static OGRE_NORETURN void throwException(Exception::ExceptionCodes code, int number, 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)
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)
#define OGRE_NORETURN
Definition: OgrePlatform.h:109
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)
virtual long getLine() const
Gets line number.
ExceptionFactory()
Private constructor, no construction.
virtual const String & getFile() const
Gets source file name.
Class implementing dispatch method in order to construct by-value exceptions of a derived type based ...
InternalErrorException(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)
_StringBase String
~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:84
InvalidParametersException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)