OGRE  1.7
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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-2011 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 "OgreHeaderPrefix.h"
34 #include "OgreString.h"
35 #include <exception>
36 
37 // Backwards compatibility with old assert mode definitions
38 #if OGRE_RELEASE_ASSERT == 1
39 # define OGRE_ASSERT_MODE 1
40 #endif
41 
42 // Check for OGRE assert mode
43 
44 // RELEASE_EXCEPTIONS mode
45 #if OGRE_ASSERT_MODE == 1
46 # ifdef _DEBUG
47 # define OgreAssert( a, b ) assert( (a) && (b) )
48 
49 # else
50 # if OGRE_COMP != OGRE_COMPILER_BORL
51 # define OgreAssert( a, b ) if( !(a) ) OGRE_EXCEPT( Ogre::Exception::ERR_RT_ASSERTION_FAILED, (b), "no function info")
52 # else
53 # define OgreAssert( a, b ) if( !(a) ) OGRE_EXCEPT( Ogre::Exception::ERR_RT_ASSERTION_FAILED, (b), __FUNC__ )
54 # endif
55 
56 # endif
57 
58 // EXCEPTIONS mode
59 #elif OGRE_ASSERT_MODE == 2
60 # if OGRE_COMP != OGRE_COMPILER_BORL
61 # define OgreAssert( a, b ) if( !(a) ) OGRE_EXCEPT( Ogre::Exception::ERR_RT_ASSERTION_FAILED, (b), "no function info")
62 # else
63 # define OgreAssert( a, b ) if( !(a) ) OGRE_EXCEPT( Ogre::Exception::ERR_RT_ASSERTION_FAILED, (b), __FUNC__ )
64 # endif
65 
66 // STANDARD mode
67 #else
68 # define OgreAssert( a, b ) assert( (a) && (b) )
69 
70 #endif
71 
72 namespace Ogre {
92  class _OgreExport Exception : public std::exception
93  {
94  protected:
95  long line;
96  int number;
101  mutable String fullDesc;
102  public:
118  ERR_NOT_IMPLEMENTED
119  };
120 
123  Exception( int number, const String& description, const String& source );
124 
127  Exception( int number, const String& description, const String& source, const char* type, const char* file, long line );
128 
131  Exception(const Exception& rhs);
132 
134  ~Exception() throw() {}
135 
138  void operator = (const Exception& rhs);
139 
150  virtual const String& getFullDescription(void) const;
151 
154  virtual int getNumber(void) const throw();
155 
158  virtual const String &getSource() const { return source; }
159 
162  virtual const String &getFile() const { return file; }
163 
166  virtual long getLine() const { return line; }
167 
172  virtual const String &getDescription(void) const { return description; }
173 
175  const char* what() const throw() { return getFullDescription().c_str(); }
176 
177  };
178 
179 
186  template <int num>
188  {
189  enum { number = num };
190  };
191 
192  // Specialised exceptions allowing each to be caught specifically
193  // backwards-compatible since exception codes still used
194 
196  {
197  public:
198  UnimplementedException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
199  : Exception(inNumber, inDescription, inSource, "UnimplementedException", inFile, inLine) {}
200  };
202  {
203  public:
204  FileNotFoundException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
205  : Exception(inNumber, inDescription, inSource, "FileNotFoundException", inFile, inLine) {}
206  };
208  {
209  public:
210  IOException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
211  : Exception(inNumber, inDescription, inSource, "IOException", inFile, inLine) {}
212  };
214  {
215  public:
216  InvalidStateException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
217  : Exception(inNumber, inDescription, inSource, "InvalidStateException", inFile, inLine) {}
218  };
220  {
221  public:
222  InvalidParametersException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
223  : Exception(inNumber, inDescription, inSource, "InvalidParametersException", inFile, inLine) {}
224  };
226  {
227  public:
228  ItemIdentityException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
229  : Exception(inNumber, inDescription, inSource, "ItemIdentityException", inFile, inLine) {}
230  };
232  {
233  public:
234  InternalErrorException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
235  : Exception(inNumber, inDescription, inSource, "InternalErrorException", inFile, inLine) {}
236  };
238  {
239  public:
240  RenderingAPIException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
241  : Exception(inNumber, inDescription, inSource, "RenderingAPIException", inFile, inLine) {}
242  };
244  {
245  public:
246  RuntimeAssertionException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
247  : Exception(inNumber, inDescription, inSource, "RuntimeAssertionException", inFile, inLine) {}
248  };
249 
250 
261  {
262  private:
265  public:
268  const String& desc,
269  const String& src, const char* file, long line)
270  {
271  return UnimplementedException(code.number, desc, src, file, line);
272  }
275  const String& desc,
276  const String& src, const char* file, long line)
277  {
278  return FileNotFoundException(code.number, desc, src, file, line);
279  }
282  const String& desc,
283  const String& src, const char* file, long line)
284  {
285  return IOException(code.number, desc, src, file, line);
286  }
289  const String& desc,
290  const String& src, const char* file, long line)
291  {
292  return InvalidStateException(code.number, desc, src, file, line);
293  }
296  const String& desc,
297  const String& src, const char* file, long line)
298  {
299  return InvalidParametersException(code.number, desc, src, file, line);
300  }
303  const String& desc,
304  const String& src, const char* file, long line)
305  {
306  return ItemIdentityException(code.number, desc, src, file, line);
307  }
310  const String& desc,
311  const String& src, const char* file, long line)
312  {
313  return ItemIdentityException(code.number, desc, src, file, line);
314  }
317  const String& desc,
318  const String& src, const char* file, long line)
319  {
320  return InternalErrorException(code.number, desc, src, file, line);
321  }
324  const String& desc,
325  const String& src, const char* file, long line)
326  {
327  return RenderingAPIException(code.number, desc, src, file, line);
328  }
331  const String& desc,
332  const String& src, const char* file, long line)
333  {
334  return RuntimeAssertionException(code.number, desc, src, file, line);
335  }
336 
337  };
338 
339 
340 
341 #ifndef OGRE_EXCEPT
342 #define OGRE_EXCEPT(num, desc, src) throw Ogre::ExceptionFactory::create( \
343  Ogre::ExceptionCodeType<num>(), desc, src, __FILE__, __LINE__ );
344 #endif
345 
348 } // Namespace Ogre
349 
350 #include "OgreHeaderSuffix.h"
351 #endif
IOException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
#define _OgreExport
Definition: OgrePlatform.h:203
UnimplementedException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
static FileNotFoundException create(ExceptionCodeType< Exception::ERR_FILE_NOT_FOUND > 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)
InvalidStateException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
static ItemIdentityException create(ExceptionCodeType< Exception::ERR_ITEM_NOT_FOUND > 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 RuntimeAssertionException create(ExceptionCodeType< Exception::ERR_RT_ASSERTION_FAILED > code, const String &desc, const String &src, const char *file, long line)
const char * what() const
Override std::exception::what.
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 'description' field of this exception.
static IOException create(ExceptionCodeType< Exception::ERR_CANNOT_WRITE_TO_FILE > code, const String &desc, const String &src, const char *file, long line)
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.
static UnimplementedException create(ExceptionCodeType< Exception::ERR_NOT_IMPLEMENTED > code, const String &desc, const String &src, const char *file, long line)
virtual const String & getFile() const
Gets source file name.
static InternalErrorException create(ExceptionCodeType< Exception::ERR_INTERNAL_ERROR > code, 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 InvalidStateException create(ExceptionCodeType< Exception::ERR_INVALID_STATE > 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)
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.
static ItemIdentityException create(ExceptionCodeType< Exception::ERR_DUPLICATE_ITEM > code, const String &desc, const String &src, const char *file, long line)
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:92
InvalidParametersException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)