OgreException.h

Go to the documentation of this file.
00001 /*
00002 -----------------------------------------------------------------------------
00003 This source file is part of OGRE
00004 (Object-oriented Graphics Rendering Engine)
00005 For the latest info, see http://www.ogre3d.org/
00006 
00007 Copyright (c) 2000-2012 Torus Knot Software Ltd
00008 
00009 Permission is hereby granted, free of charge, to any person obtaining a copy
00010 of this software and associated documentation files (the "Software"), to deal
00011 in the Software without restriction, including without limitation the rights
00012 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00013 copies of the Software, and to permit persons to whom the Software is
00014 furnished to do so, subject to the following conditions:
00015 
00016 The above copyright notice and this permission notice shall be included in
00017 all copies or substantial portions of the Software.
00018 
00019 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00020 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00022 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00024 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00025 THE SOFTWARE.
00026 -----------------------------------------------------------------------------
00027 */
00028 #ifndef __Exception_H_
00029 #define __Exception_H_
00030 
00031 // Precompiler options
00032 #include "OgrePrerequisites.h"
00033 #include "OgreHeaderPrefix.h"
00034 #include "OgreString.h"
00035 #include <exception>
00036 
00037 // Backwards compatibility with old assert mode definitions
00038 #if OGRE_RELEASE_ASSERT == 1
00039 #   define OGRE_ASSERT_MODE 1
00040 #endif
00041 
00042 // Check for OGRE assert mode
00043 
00044 // RELEASE_EXCEPTIONS mode
00045 #if OGRE_ASSERT_MODE == 1
00046 #   ifdef _DEBUG
00047 #       define OgreAssert( a, b ) assert( (a) && (b) )
00048 
00049 #   else
00050 #       if OGRE_COMP != OGRE_COMPILER_BORL
00051 #           define OgreAssert( a, b ) if( !(a) ) OGRE_EXCEPT( Ogre::Exception::ERR_RT_ASSERTION_FAILED, (b), "no function info")
00052 #       else
00053 #           define OgreAssert( a, b ) if( !(a) ) OGRE_EXCEPT( Ogre::Exception::ERR_RT_ASSERTION_FAILED, (b), __FUNC__ )
00054 #       endif
00055 
00056 #   endif
00057 
00058 // EXCEPTIONS mode
00059 #elif OGRE_ASSERT_MODE == 2
00060 #   if OGRE_COMP != OGRE_COMPILER_BORL
00061 #       define OgreAssert( a, b ) if( !(a) ) OGRE_EXCEPT( Ogre::Exception::ERR_RT_ASSERTION_FAILED, (b), "no function info")
00062 #   else
00063 #       define OgreAssert( a, b ) if( !(a) ) OGRE_EXCEPT( Ogre::Exception::ERR_RT_ASSERTION_FAILED, (b), __FUNC__ )
00064 #   endif
00065 
00066 // STANDARD mode
00067 #else
00068 #   define OgreAssert( a, b ) assert( (a) && (b) )
00069 
00070 #endif
00071 
00072 namespace Ogre {
00092     class _OgreExport Exception : public std::exception
00093     {
00094     protected:
00095         long line;
00096         int number;
00097         String typeName;
00098         String description;
00099         String source;
00100         String file;
00101         mutable String fullDesc;
00102     public:
00108         enum ExceptionCodes {
00109             ERR_CANNOT_WRITE_TO_FILE,
00110             ERR_INVALID_STATE,
00111             ERR_INVALIDPARAMS,
00112             ERR_RENDERINGAPI_ERROR,
00113             ERR_DUPLICATE_ITEM,
00114             ERR_ITEM_NOT_FOUND,
00115             ERR_FILE_NOT_FOUND,
00116             ERR_INTERNAL_ERROR,
00117             ERR_RT_ASSERTION_FAILED, 
00118             ERR_NOT_IMPLEMENTED
00119         };
00120 
00123         Exception( int number, const String& description, const String& source );
00124 
00127         Exception( int number, const String& description, const String& source, const char* type, const char* file, long line );
00128 
00131         Exception(const Exception& rhs);
00132 
00134         ~Exception() throw() {}
00135 
00138         void operator = (const Exception& rhs);
00139 
00150         virtual const String& getFullDescription(void) const;
00151 
00154         virtual int getNumber(void) const throw();
00155 
00158         virtual const String &getSource() const { return source; }
00159 
00162         virtual const String &getFile() const { return file; }
00163 
00166         virtual long getLine() const { return line; }
00167 
00172         virtual const String &getDescription(void) const { return description; }
00173 
00175         const char* what() const throw() { return getFullDescription().c_str(); }
00176         
00177     };
00178 
00179 
00186     template <int num>
00187     struct ExceptionCodeType
00188     {
00189         enum { number = num };
00190     };
00191 
00192     // Specialised exceptions allowing each to be caught specifically
00193     // backwards-compatible since exception codes still used
00194 
00195     class _OgreExport UnimplementedException : public Exception 
00196     {
00197     public:
00198         UnimplementedException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
00199             : Exception(inNumber, inDescription, inSource, "UnimplementedException", inFile, inLine) {}
00200     };
00201     class _OgreExport FileNotFoundException : public Exception
00202     {
00203     public:
00204         FileNotFoundException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
00205             : Exception(inNumber, inDescription, inSource, "FileNotFoundException", inFile, inLine) {}
00206     };
00207     class _OgreExport IOException : public Exception
00208     {
00209     public:
00210         IOException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
00211             : Exception(inNumber, inDescription, inSource, "IOException", inFile, inLine) {}
00212     };
00213     class _OgreExport InvalidStateException : public Exception
00214     {
00215     public:
00216         InvalidStateException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
00217             : Exception(inNumber, inDescription, inSource, "InvalidStateException", inFile, inLine) {}
00218     };
00219     class _OgreExport InvalidParametersException : public Exception
00220     {
00221     public:
00222         InvalidParametersException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
00223             : Exception(inNumber, inDescription, inSource, "InvalidParametersException", inFile, inLine) {}
00224     };
00225     class _OgreExport ItemIdentityException : public Exception
00226     {
00227     public:
00228         ItemIdentityException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
00229             : Exception(inNumber, inDescription, inSource, "ItemIdentityException", inFile, inLine) {}
00230     };
00231     class _OgreExport InternalErrorException : public Exception
00232     {
00233     public:
00234         InternalErrorException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
00235             : Exception(inNumber, inDescription, inSource, "InternalErrorException", inFile, inLine) {}
00236     };
00237     class _OgreExport RenderingAPIException : public Exception
00238     {
00239     public:
00240         RenderingAPIException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
00241             : Exception(inNumber, inDescription, inSource, "RenderingAPIException", inFile, inLine) {}
00242     };
00243     class _OgreExport RuntimeAssertionException : public Exception
00244     {
00245     public:
00246         RuntimeAssertionException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
00247             : Exception(inNumber, inDescription, inSource, "RuntimeAssertionException", inFile, inLine) {}
00248     };
00249 
00250 
00260     class ExceptionFactory
00261     {
00262     private:
00264         ExceptionFactory() {}
00265     public:
00266         static UnimplementedException create(
00267             ExceptionCodeType<Exception::ERR_NOT_IMPLEMENTED> code, 
00268             const String& desc, 
00269             const String& src, const char* file, long line)
00270         {
00271             return UnimplementedException(code.number, desc, src, file, line);
00272         }
00273         static FileNotFoundException create(
00274             ExceptionCodeType<Exception::ERR_FILE_NOT_FOUND> code, 
00275             const String& desc, 
00276             const String& src, const char* file, long line)
00277         {
00278             return FileNotFoundException(code.number, desc, src, file, line);
00279         }
00280         static IOException create(
00281             ExceptionCodeType<Exception::ERR_CANNOT_WRITE_TO_FILE> code, 
00282             const String& desc, 
00283             const String& src, const char* file, long line)
00284         {
00285             return IOException(code.number, desc, src, file, line);
00286         }
00287         static InvalidStateException create(
00288             ExceptionCodeType<Exception::ERR_INVALID_STATE> code, 
00289             const String& desc, 
00290             const String& src, const char* file, long line)
00291         {
00292             return InvalidStateException(code.number, desc, src, file, line);
00293         }
00294         static InvalidParametersException create(
00295             ExceptionCodeType<Exception::ERR_INVALIDPARAMS> code, 
00296             const String& desc, 
00297             const String& src, const char* file, long line)
00298         {
00299             return InvalidParametersException(code.number, desc, src, file, line);
00300         }
00301         static ItemIdentityException create(
00302             ExceptionCodeType<Exception::ERR_ITEM_NOT_FOUND> code, 
00303             const String& desc, 
00304             const String& src, const char* file, long line)
00305         {
00306             return ItemIdentityException(code.number, desc, src, file, line);
00307         }
00308         static ItemIdentityException create(
00309             ExceptionCodeType<Exception::ERR_DUPLICATE_ITEM> code, 
00310             const String& desc, 
00311             const String& src, const char* file, long line)
00312         {
00313             return ItemIdentityException(code.number, desc, src, file, line);
00314         }
00315         static InternalErrorException create(
00316             ExceptionCodeType<Exception::ERR_INTERNAL_ERROR> code, 
00317             const String& desc, 
00318             const String& src, const char* file, long line)
00319         {
00320             return InternalErrorException(code.number, desc, src, file, line);
00321         }
00322         static RenderingAPIException create(
00323             ExceptionCodeType<Exception::ERR_RENDERINGAPI_ERROR> code, 
00324             const String& desc, 
00325             const String& src, const char* file, long line)
00326         {
00327             return RenderingAPIException(code.number, desc, src, file, line);
00328         }
00329         static RuntimeAssertionException create(
00330             ExceptionCodeType<Exception::ERR_RT_ASSERTION_FAILED> code, 
00331             const String& desc, 
00332             const String& src, const char* file, long line)
00333         {
00334             return RuntimeAssertionException(code.number, desc, src, file, line);
00335         }
00336 
00337     };
00338     
00339 
00340     
00341 #ifndef OGRE_EXCEPT
00342 #define OGRE_EXCEPT(num, desc, src) throw Ogre::ExceptionFactory::create( \
00343     Ogre::ExceptionCodeType<num>(), desc, src, __FILE__, __LINE__ );
00344 #endif
00345 
00348 } // Namespace Ogre
00349 
00350 #include "OgreHeaderSuffix.h"
00351 #endif

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 Fri May 25 23:36:24 2012