OgreException.h
Go to the documentation of this file.
/*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2013 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef __Exception_H_
#define __Exception_H_
// Precompiler options
#include "OgrePrerequisites.h"
#include "OgreString.h"
#include <exception>
#include "OgreHeaderPrefix.h"
// Check for OGRE assert mode
// RELEASE_EXCEPTIONS mode
#if OGRE_ASSERT_MODE == 1
# if OGRE_DEBUG_MODE
# define OgreAssert( a, b ) assert( (a) && (b) )
# else
# if OGRE_COMP != OGRE_COMPILER_BORL
# define OgreAssert( a, b ) if( !(a) ) OGRE_EXCEPT( Ogre::Exception::ERR_RT_ASSERTION_FAILED, (b), "no function info")
# else
# define OgreAssert( a, b ) if( !(a) ) OGRE_EXCEPT( Ogre::Exception::ERR_RT_ASSERTION_FAILED, (b), __FUNC__ )
# endif
# endif
// EXCEPTIONS mode
#elif OGRE_ASSERT_MODE == 2
# if OGRE_COMP != OGRE_COMPILER_BORL
# define OgreAssert( a, b ) if( !(a) ) OGRE_EXCEPT( Ogre::Exception::ERR_RT_ASSERTION_FAILED, (b), "no function info")
# else
# define OgreAssert( a, b ) if( !(a) ) OGRE_EXCEPT( Ogre::Exception::ERR_RT_ASSERTION_FAILED, (b), __FUNC__ )
# endif
// STANDARD mode
#else
# define OgreAssert( a, b ) assert( (a) && (b) )
#endif
namespace Ogre {
class _OgreExport Exception : public std::exception
{
protected:
long line;
int number;
String typeName;
String description;
String source;
String file;
mutable String fullDesc;
public:
enum ExceptionCodes {
ERR_CANNOT_WRITE_TO_FILE,
ERR_INVALID_STATE,
ERR_INVALIDPARAMS,
ERR_RENDERINGAPI_ERROR,
ERR_DUPLICATE_ITEM,
ERR_ITEM_NOT_FOUND,
ERR_FILE_NOT_FOUND,
ERR_INTERNAL_ERROR,
ERR_RT_ASSERTION_FAILED,
ERR_NOT_IMPLEMENTED
};
Exception( int number, const String& description, const String& source );
Exception( int number, const String& description, const String& source, const char* type, const char* file, long line );
Exception(const Exception& rhs);
~Exception() throw() {}
void operator = (const Exception& rhs);
virtual const String& getFullDescription(void) const;
virtual int getNumber(void) const throw();
virtual const String &getSource() const { return source; }
virtual const String &getFile() const { return file; }
virtual long getLine() const { return line; }
virtual const String &getDescription(void) const { return description; }
const char* what() const throw() { return getFullDescription().c_str(); }
};
template <int num>
struct ExceptionCodeType
{
enum { number = num };
};
// Specialised exceptions allowing each to be caught specifically
// backwards-compatible since exception codes still used
class _OgreExport UnimplementedException : public Exception
{
public:
UnimplementedException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
: Exception(inNumber, inDescription, inSource, "UnimplementedException", inFile, inLine) {}
};
class _OgreExport FileNotFoundException : public Exception
{
public:
FileNotFoundException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
: Exception(inNumber, inDescription, inSource, "FileNotFoundException", inFile, inLine) {}
};
class _OgreExport IOException : public Exception
{
public:
IOException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
: Exception(inNumber, inDescription, inSource, "IOException", inFile, inLine) {}
};
class _OgreExport InvalidStateException : public Exception
{
public:
InvalidStateException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
: Exception(inNumber, inDescription, inSource, "InvalidStateException", inFile, inLine) {}
};
class _OgreExport InvalidParametersException : public Exception
{
public:
InvalidParametersException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
: Exception(inNumber, inDescription, inSource, "InvalidParametersException", inFile, inLine) {}
};
class _OgreExport ItemIdentityException : public Exception
{
public:
ItemIdentityException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
: Exception(inNumber, inDescription, inSource, "ItemIdentityException", inFile, inLine) {}
};
class _OgreExport InternalErrorException : public Exception
{
public:
InternalErrorException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
: Exception(inNumber, inDescription, inSource, "InternalErrorException", inFile, inLine) {}
};
class _OgreExport RenderingAPIException : public Exception
{
public:
RenderingAPIException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
: Exception(inNumber, inDescription, inSource, "RenderingAPIException", inFile, inLine) {}
};
class _OgreExport RuntimeAssertionException : public Exception
{
public:
RuntimeAssertionException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
: Exception(inNumber, inDescription, inSource, "RuntimeAssertionException", inFile, inLine) {}
};
class ExceptionFactory
{
private:
ExceptionFactory() {}
public:
static UnimplementedException create(
ExceptionCodeType<Exception::ERR_NOT_IMPLEMENTED> code,
const String& desc,
const String& src, const char* file, long line)
{
return UnimplementedException(code.number, desc, src, file, line);
}
static FileNotFoundException create(
ExceptionCodeType<Exception::ERR_FILE_NOT_FOUND> code,
const String& desc,
const String& src, const char* file, long line)
{
return FileNotFoundException(code.number, desc, src, file, line);
}
static IOException create(
ExceptionCodeType<Exception::ERR_CANNOT_WRITE_TO_FILE> code,
const String& desc,
const String& src, const char* file, long line)
{
return IOException(code.number, desc, src, file, line);
}
static InvalidStateException create(
ExceptionCodeType<Exception::ERR_INVALID_STATE> code,
const String& desc,
const String& src, const char* file, long line)
{
return InvalidStateException(code.number, desc, src, file, line);
}
static InvalidParametersException create(
ExceptionCodeType<Exception::ERR_INVALIDPARAMS> code,
const String& desc,
const String& src, const char* file, long line)
{
return InvalidParametersException(code.number, desc, src, file, line);
}
static ItemIdentityException create(
ExceptionCodeType<Exception::ERR_ITEM_NOT_FOUND> code,
const String& desc,
const String& src, const char* file, long line)
{
return ItemIdentityException(code.number, desc, src, file, line);
}
static ItemIdentityException create(
ExceptionCodeType<Exception::ERR_DUPLICATE_ITEM> code,
const String& desc,
const String& src, const char* file, long line)
{
return ItemIdentityException(code.number, desc, src, file, line);
}
static InternalErrorException create(
ExceptionCodeType<Exception::ERR_INTERNAL_ERROR> code,
const String& desc,
const String& src, const char* file, long line)
{
return InternalErrorException(code.number, desc, src, file, line);
}
static RenderingAPIException create(
ExceptionCodeType<Exception::ERR_RENDERINGAPI_ERROR> code,
const String& desc,
const String& src, const char* file, long line)
{
return RenderingAPIException(code.number, desc, src, file, line);
}
static RuntimeAssertionException create(
ExceptionCodeType<Exception::ERR_RT_ASSERTION_FAILED> code,
const String& desc,
const String& src, const char* file, long line)
{
return RuntimeAssertionException(code.number, desc, src, file, line);
}
};
#ifndef OGRE_EXCEPT
#define OGRE_EXCEPT(num, desc, src) throw Ogre::ExceptionFactory::create( \
Ogre::ExceptionCodeType<num>(), desc, src, __FILE__, __LINE__ );
#endif
} // Namespace Ogre
#include "OgreHeaderSuffix.h"
#endif
Ogre::RuntimeAssertionException
Definition: OgreException.h:235
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 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::Exception::description
String description
Definition: OgreException.h:90
Ogre::Exception::ERR_FILE_NOT_FOUND
Definition: OgreException.h:107
_OgreExport
#define _OgreExport
Definition: OgrePlatform.h:257
Ogre::Exception::ERR_RT_ASSERTION_FAILED
Definition: OgreException.h:109
Ogre::Exception::~Exception
~Exception()
Needed for compatibility with std::exception.
Definition: OgreException.h:126
Ogre::ExceptionCodeType::number
Definition: OgreException.h:181
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::InternalErrorException
Definition: OgreException.h:223
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::Exception::getLine
virtual long getLine() const
Gets line number.
Definition: OgreException.h:158
Ogre::Exception::typeName
String typeName
Definition: OgreException.h:89
Ogre::RenderingAPIException::RenderingAPIException
RenderingAPIException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
Definition: OgreException.h:232
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
OgreString.h
Ogre::UnimplementedException
Definition: OgreException.h:187
Ogre::ExceptionFactory
Class implementing dispatch methods in order to construct by-value exceptions of a derived type based...
Definition: OgreException.h:252
Ogre::Exception::ERR_RENDERINGAPI_ERROR
Definition: OgreException.h:104
Ogre::Exception
When thrown, provides information about an error that has occurred inside the engine.
Definition: OgreException.h:84
Ogre::InvalidStateException
Definition: OgreException.h:205
Ogre::InternalErrorException::InternalErrorException
InternalErrorException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
Definition: OgreException.h:226
Ogre::Exception::line
long line
Definition: OgreException.h:87
Ogre::UnimplementedException::UnimplementedException
UnimplementedException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
Definition: OgreException.h:190
Ogre::Exception::ERR_INTERNAL_ERROR
Definition: OgreException.h:108
Ogre::ItemIdentityException
Definition: OgreException.h:217
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::Exception::ERR_DUPLICATE_ITEM
Definition: OgreException.h:105
OgrePrerequisites.h
Ogre::Exception::what
const char * what() const
Override std::exception::what.
Definition: OgreException.h:167
Ogre::Exception::getDescription
virtual const String & getDescription(void) const
Returns a string with only the &#39;description&#39; field of this exception.
Definition: OgreException.h:164
Ogre::String
_StringBase String
Definition: OgrePrerequisites.h:439
Ogre::IOException
Definition: OgreException.h:199
Ogre::ExceptionFactory::ExceptionFactory
ExceptionFactory()
Private constructor, no construction.
Definition: OgreException.h:256
Ogre::InvalidStateException::InvalidStateException
InvalidStateException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
Definition: OgreException.h:208
OgreHeaderSuffix.h
Ogre::IOException::IOException
IOException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
Definition: OgreException.h:202
Ogre::Exception::ERR_INVALID_STATE
Definition: OgreException.h:102
Ogre::Exception::getFile
virtual const String & getFile() const
Gets source file name.
Definition: OgreException.h:154
Ogre::FileNotFoundException
Definition: OgreException.h:193
Ogre::Exception::getSource
virtual const String & getSource() const
Gets the source function.
Definition: OgreException.h:150
Ogre::Exception::ExceptionCodes
ExceptionCodes
Static definitions of error codes.
Definition: OgreException.h:100
Ogre::Exception::ERR_ITEM_NOT_FOUND
Definition: OgreException.h:106
Ogre::Exception::ERR_INVALIDPARAMS
Definition: OgreException.h:103
Ogre
Definition: OgreAndroidLogListener.h:34
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::InvalidParametersException
Definition: OgreException.h:211
Ogre::Exception::number
int number
Definition: OgreException.h:88
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::ItemIdentityException::ItemIdentityException
ItemIdentityException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
Definition: OgreException.h:220
Ogre::Exception::ERR_CANNOT_WRITE_TO_FILE
Definition: OgreException.h:101
OgreHeaderPrefix.h
Ogre::RuntimeAssertionException::RuntimeAssertionException
RuntimeAssertionException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
Definition: OgreException.h:238
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::fullDesc
String fullDesc
Definition: OgreException.h:93
Ogre::Exception::source
String source
Definition: OgreException.h:91
Ogre::ExceptionCodeType
Template struct which creates a distinct type for each exception code.
Definition: OgreException.h:179
Ogre::Exception::file
String file
Definition: OgreException.h:92
Ogre::InvalidParametersException::InvalidParametersException
InvalidParametersException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
Definition: OgreException.h:214
Ogre::FileNotFoundException::FileNotFoundException
FileNotFoundException(int inNumber, const String &inDescription, const String &inSource, const char *inFile, long inLine)
Definition: OgreException.h:196
Ogre::RenderingAPIException
Definition: OgreException.h:229
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

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