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-2013 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 "OgreString.h"
00034 #include <exception>
00035 #include "OgreHeaderPrefix.h"
00036 
00037 // Check for OGRE assert mode
00038 
00039 // RELEASE_EXCEPTIONS mode
00040 #if OGRE_ASSERT_MODE == 1
00041 #   if OGRE_DEBUG_MODE
00042 #       define OgreAssert( a, b ) assert( (a) && (b) )
00043 #   else
00044 #       if OGRE_COMP != OGRE_COMPILER_BORL
00045 #           define OgreAssert( a, b ) if( !(a) ) OGRE_EXCEPT( Ogre::Exception::ERR_RT_ASSERTION_FAILED, (b), "no function info")
00046 #       else
00047 #           define OgreAssert( a, b ) if( !(a) ) OGRE_EXCEPT( Ogre::Exception::ERR_RT_ASSERTION_FAILED, (b), __FUNC__ )
00048 #       endif
00049 #   endif
00050 
00051 // EXCEPTIONS mode
00052 #elif OGRE_ASSERT_MODE == 2
00053 #   if OGRE_COMP != OGRE_COMPILER_BORL
00054 #       define OgreAssert( a, b ) if( !(a) ) OGRE_EXCEPT( Ogre::Exception::ERR_RT_ASSERTION_FAILED, (b), "no function info")
00055 #   else
00056 #       define OgreAssert( a, b ) if( !(a) ) OGRE_EXCEPT( Ogre::Exception::ERR_RT_ASSERTION_FAILED, (b), __FUNC__ )
00057 #   endif
00058 
00059 // STANDARD mode
00060 #else
00061 #   define OgreAssert( a, b ) assert( (a) && (b) )
00062 #endif
00063 
00064 namespace Ogre {
00084     class _OgreExport Exception : public std::exception
00085     {
00086     protected:
00087         long line;
00088         int number;
00089         String typeName;
00090         String description;
00091         String source;
00092         String file;
00093         mutable String fullDesc;
00094     public:
00100         enum ExceptionCodes {
00101             ERR_CANNOT_WRITE_TO_FILE,
00102             ERR_INVALID_STATE,
00103             ERR_INVALIDPARAMS,
00104             ERR_RENDERINGAPI_ERROR,
00105             ERR_DUPLICATE_ITEM,
00106             ERR_ITEM_NOT_FOUND,
00107             ERR_FILE_NOT_FOUND,
00108             ERR_INTERNAL_ERROR,
00109             ERR_RT_ASSERTION_FAILED, 
00110             ERR_NOT_IMPLEMENTED
00111         };
00112 
00115         Exception( int number, const String& description, const String& source );
00116 
00119         Exception( int number, const String& description, const String& source, const char* type, const char* file, long line );
00120 
00123         Exception(const Exception& rhs);
00124 
00126         ~Exception() throw() {}
00127 
00130         void operator = (const Exception& rhs);
00131 
00142         virtual const String& getFullDescription(void) const;
00143 
00146         virtual int getNumber(void) const throw();
00147 
00150         virtual const String &getSource() const { return source; }
00151 
00154         virtual const String &getFile() const { return file; }
00155 
00158         virtual long getLine() const { return line; }
00159 
00164         virtual const String &getDescription(void) const { return description; }
00165 
00167         const char* what() const throw() { return getFullDescription().c_str(); }
00168         
00169     };
00170 
00171 
00178     template <int num>
00179     struct ExceptionCodeType
00180     {
00181         enum { number = num };
00182     };
00183 
00184     // Specialised exceptions allowing each to be caught specifically
00185     // backwards-compatible since exception codes still used
00186 
00187     class _OgreExport UnimplementedException : public Exception 
00188     {
00189     public:
00190         UnimplementedException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
00191             : Exception(inNumber, inDescription, inSource, "UnimplementedException", inFile, inLine) {}
00192     };
00193     class _OgreExport FileNotFoundException : public Exception
00194     {
00195     public:
00196         FileNotFoundException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
00197             : Exception(inNumber, inDescription, inSource, "FileNotFoundException", inFile, inLine) {}
00198     };
00199     class _OgreExport IOException : public Exception
00200     {
00201     public:
00202         IOException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
00203             : Exception(inNumber, inDescription, inSource, "IOException", inFile, inLine) {}
00204     };
00205     class _OgreExport InvalidStateException : public Exception
00206     {
00207     public:
00208         InvalidStateException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
00209             : Exception(inNumber, inDescription, inSource, "InvalidStateException", inFile, inLine) {}
00210     };
00211     class _OgreExport InvalidParametersException : public Exception
00212     {
00213     public:
00214         InvalidParametersException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
00215             : Exception(inNumber, inDescription, inSource, "InvalidParametersException", inFile, inLine) {}
00216     };
00217     class _OgreExport ItemIdentityException : public Exception
00218     {
00219     public:
00220         ItemIdentityException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
00221             : Exception(inNumber, inDescription, inSource, "ItemIdentityException", inFile, inLine) {}
00222     };
00223     class _OgreExport InternalErrorException : public Exception
00224     {
00225     public:
00226         InternalErrorException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
00227             : Exception(inNumber, inDescription, inSource, "InternalErrorException", inFile, inLine) {}
00228     };
00229     class _OgreExport RenderingAPIException : public Exception
00230     {
00231     public:
00232         RenderingAPIException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
00233             : Exception(inNumber, inDescription, inSource, "RenderingAPIException", inFile, inLine) {}
00234     };
00235     class _OgreExport RuntimeAssertionException : public Exception
00236     {
00237     public:
00238         RuntimeAssertionException(int inNumber, const String& inDescription, const String& inSource, const char* inFile, long inLine)
00239             : Exception(inNumber, inDescription, inSource, "RuntimeAssertionException", inFile, inLine) {}
00240     };
00241 
00242 
00252     class ExceptionFactory
00253     {
00254     private:
00256         ExceptionFactory() {}
00257     public:
00258         static UnimplementedException create(
00259             ExceptionCodeType<Exception::ERR_NOT_IMPLEMENTED> code, 
00260             const String& desc, 
00261             const String& src, const char* file, long line)
00262         {
00263             return UnimplementedException(code.number, desc, src, file, line);
00264         }
00265         static FileNotFoundException create(
00266             ExceptionCodeType<Exception::ERR_FILE_NOT_FOUND> code, 
00267             const String& desc, 
00268             const String& src, const char* file, long line)
00269         {
00270             return FileNotFoundException(code.number, desc, src, file, line);
00271         }
00272         static IOException create(
00273             ExceptionCodeType<Exception::ERR_CANNOT_WRITE_TO_FILE> code, 
00274             const String& desc, 
00275             const String& src, const char* file, long line)
00276         {
00277             return IOException(code.number, desc, src, file, line);
00278         }
00279         static InvalidStateException create(
00280             ExceptionCodeType<Exception::ERR_INVALID_STATE> code, 
00281             const String& desc, 
00282             const String& src, const char* file, long line)
00283         {
00284             return InvalidStateException(code.number, desc, src, file, line);
00285         }
00286         static InvalidParametersException create(
00287             ExceptionCodeType<Exception::ERR_INVALIDPARAMS> code, 
00288             const String& desc, 
00289             const String& src, const char* file, long line)
00290         {
00291             return InvalidParametersException(code.number, desc, src, file, line);
00292         }
00293         static ItemIdentityException create(
00294             ExceptionCodeType<Exception::ERR_ITEM_NOT_FOUND> code, 
00295             const String& desc, 
00296             const String& src, const char* file, long line)
00297         {
00298             return ItemIdentityException(code.number, desc, src, file, line);
00299         }
00300         static ItemIdentityException create(
00301             ExceptionCodeType<Exception::ERR_DUPLICATE_ITEM> code, 
00302             const String& desc, 
00303             const String& src, const char* file, long line)
00304         {
00305             return ItemIdentityException(code.number, desc, src, file, line);
00306         }
00307         static InternalErrorException create(
00308             ExceptionCodeType<Exception::ERR_INTERNAL_ERROR> code, 
00309             const String& desc, 
00310             const String& src, const char* file, long line)
00311         {
00312             return InternalErrorException(code.number, desc, src, file, line);
00313         }
00314         static RenderingAPIException create(
00315             ExceptionCodeType<Exception::ERR_RENDERINGAPI_ERROR> code, 
00316             const String& desc, 
00317             const String& src, const char* file, long line)
00318         {
00319             return RenderingAPIException(code.number, desc, src, file, line);
00320         }
00321         static RuntimeAssertionException create(
00322             ExceptionCodeType<Exception::ERR_RT_ASSERTION_FAILED> code, 
00323             const String& desc, 
00324             const String& src, const char* file, long line)
00325         {
00326             return RuntimeAssertionException(code.number, desc, src, file, line);
00327         }
00328 
00329     };
00330     
00331 
00332     
00333 #ifndef OGRE_EXCEPT
00334 #define OGRE_EXCEPT(num, desc, src) throw Ogre::ExceptionFactory::create( \
00335     Ogre::ExceptionCodeType<num>(), desc, src, __FILE__, __LINE__ );
00336 #endif
00337 
00340 } // Namespace Ogre
00341 
00342 #include "OgreHeaderSuffix.h"
00343 
00344 #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 Mon Jul 27 2020 13:40:42