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 
187  class _OgreExport UnimplementedException : public Exception
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  };
193  class _OgreExport FileNotFoundException : public Exception
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  };
199  class _OgreExport IOException : public Exception
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  };
205  class _OgreExport InvalidStateException : public Exception
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  };
211  class _OgreExport InvalidParametersException : public Exception
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  };
217  class _OgreExport ItemIdentityException : public Exception
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  };
223  class _OgreExport InternalErrorException : public Exception
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  };
229  class _OgreExport RenderingAPIException : public Exception
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  };
235  class _OgreExport RuntimeAssertionException : public Exception
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
OgreHeaderSuffix.h
Ogre::Exception::ERR_RENDERINGAPI_ERROR
@ ERR_RENDERINGAPI_ERROR
Definition: OgreException.h:104
Ogre::Exception::ERR_CANNOT_WRITE_TO_FILE
@ ERR_CANNOT_WRITE_TO_FILE
Definition: OgreException.h:101
Ogre::ItemIdentityException::ItemIdentityException
ItemIdentityException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
Definition: OgreException.h:220
Ogre::RenderingAPIException
Definition: OgreException.h:229
Ogre::RuntimeAssertionException::RuntimeAssertionException
RuntimeAssertionException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
Definition: OgreException.h:238
Ogre::Exception::ERR_INVALID_STATE
@ ERR_INVALID_STATE
Definition: OgreException.h:102
Ogre::Exception::getLine
virtual long getLine() const
Gets line number.
Definition: OgreException.h:158
Ogre
Definition: OgreAndroidLogListener.h:34
Ogre::RenderingAPIException::RenderingAPIException
RenderingAPIException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
Definition: OgreException.h:232
Ogre::Exception::ERR_INTERNAL_ERROR
@ ERR_INTERNAL_ERROR
Definition: OgreException.h:108
Ogre::Exception::source
String source
Definition: OgreException.h:91
Ogre::Exception::ERR_DUPLICATE_ITEM
@ ERR_DUPLICATE_ITEM
Definition: OgreException.h:105
Ogre::Exception::file
String file
Definition: OgreException.h:92
Ogre::Exception::what
const char * what() const
Override std::exception::what.
Definition: OgreException.h:167
Ogre::Exception
When thrown, provides information about an error that has occurred inside the engine.
Definition: OgreException.h:84
Ogre::ExceptionFactory::create
static InternalErrorException create(ExceptionCodeType< Exception::ERR_INTERNAL_ERROR > code, const String &desc, const String &src, const char *file, long line)
Definition: OgreException.h:307
Ogre::ExceptionFactory::create
static FileNotFoundException create(ExceptionCodeType< Exception::ERR_FILE_NOT_FOUND > code, const String &desc, const String &src, const char *file, long line)
Definition: OgreException.h:265
Ogre::UnimplementedException
Definition: OgreException.h:187
Ogre::IOException
Definition: OgreException.h:199
Ogre::ItemIdentityException
Definition: OgreException.h:217
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::ExceptionFactory::ExceptionFactory
ExceptionFactory()
Private constructor, no construction.
Definition: OgreException.h:256
Ogre::ExceptionCodeType::number
@ number
Definition: OgreException.h:181
Ogre::Exception::ERR_FILE_NOT_FOUND
@ ERR_FILE_NOT_FOUND
Definition: OgreException.h:107
Ogre::InvalidStateException::InvalidStateException
InvalidStateException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
Definition: OgreException.h:208
Ogre::InvalidParametersException::InvalidParametersException
InvalidParametersException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
Definition: OgreException.h:214
Ogre::ExceptionFactory::create
static UnimplementedException create(ExceptionCodeType< Exception::ERR_NOT_IMPLEMENTED > code, const String &desc, const String &src, const char *file, long line)
Definition: OgreException.h:258
Ogre::Exception::~Exception
~Exception()
Needed for compatibility with std::exception.
Definition: OgreException.h:126
Ogre::ExceptionFactory::create
static InvalidParametersException create(ExceptionCodeType< Exception::ERR_INVALIDPARAMS > code, const String &desc, const String &src, const char *file, long line)
Definition: OgreException.h:286
Ogre::RuntimeAssertionException
Definition: OgreException.h:235
OgreHeaderPrefix.h
Ogre::UnimplementedException::UnimplementedException
UnimplementedException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
Definition: OgreException.h:190
OgrePrerequisites.h
Ogre::Exception::number
int number
Definition: OgreException.h:88
Ogre::Exception::line
long line
Definition: OgreException.h:87
Ogre::Exception::ERR_RT_ASSERTION_FAILED
@ ERR_RT_ASSERTION_FAILED
Definition: OgreException.h:109
Ogre::ExceptionCodeType
Template struct which creates a distinct type for each exception code.
Definition: OgreException.h:179
Ogre::Exception::getFile
virtual const String & getFile() const
Gets source file name.
Definition: OgreException.h:154
Ogre::Exception::ERR_ITEM_NOT_FOUND
@ ERR_ITEM_NOT_FOUND
Definition: OgreException.h:106
Ogre::InternalErrorException
Definition: OgreException.h:223
Ogre::InvalidStateException
Definition: OgreException.h:205
Ogre::ExceptionFactory::create
static ItemIdentityException create(ExceptionCodeType< Exception::ERR_DUPLICATE_ITEM > code, const String &desc, const String &src, const char *file, long line)
Definition: OgreException.h:300
Ogre::FileNotFoundException::FileNotFoundException
FileNotFoundException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
Definition: OgreException.h:196
Ogre::Exception::fullDesc
String fullDesc
Definition: OgreException.h:93
Ogre::ExceptionFactory
Class implementing dispatch methods in order to construct by-value exceptions of a derived type based...
Definition: OgreException.h:252
Ogre::IOException::IOException
IOException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
Definition: OgreException.h:202
Ogre::FileNotFoundException
Definition: OgreException.h:193
Ogre::ExceptionFactory::create
static RuntimeAssertionException create(ExceptionCodeType< Exception::ERR_RT_ASSERTION_FAILED > code, const String &desc, const String &src, const char *file, long line)
Definition: OgreException.h:321
Ogre::ExceptionFactory::create
static RenderingAPIException create(ExceptionCodeType< Exception::ERR_RENDERINGAPI_ERROR > code, const String &desc, const String &src, const char *file, long line)
Definition: OgreException.h:314
Ogre::ExceptionFactory::create
static ItemIdentityException create(ExceptionCodeType< Exception::ERR_ITEM_NOT_FOUND > code, const String &desc, const String &src, const char *file, long line)
Definition: OgreException.h:293
Ogre::ExceptionFactory::create
static IOException create(ExceptionCodeType< Exception::ERR_CANNOT_WRITE_TO_FILE > code, const String &desc, const String &src, const char *file, long line)
Definition: OgreException.h:272
Ogre::Exception::getDescription
virtual const String & getDescription(void) const
Returns a string with only the 'description' field of this exception.
Definition: OgreException.h:164
Ogre::InvalidParametersException
Definition: OgreException.h:211
Ogre::Exception::ExceptionCodes
ExceptionCodes
Static definitions of error codes.
Definition: OgreException.h:100
Ogre::Exception::ERR_INVALIDPARAMS
@ ERR_INVALIDPARAMS
Definition: OgreException.h:103
OgreString.h
Ogre::ExceptionFactory::create
static InvalidStateException create(ExceptionCodeType< Exception::ERR_INVALID_STATE > code, const String &desc, const String &src, const char *file, long line)
Definition: OgreException.h:279
Ogre::Exception::description
String description
Definition: OgreException.h:90
Ogre::InternalErrorException::InternalErrorException
InternalErrorException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
Definition: OgreException.h:226
Ogre::Exception::getSource
virtual const String & getSource() const
Gets the source function.
Definition: OgreException.h:150
Ogre::Exception::typeName
String typeName
Definition: OgreException.h:89

Copyright © 2012 Torus Knot Software Ltd
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Last modified Tue Apr 13 2021 08:53:15