Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

# 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-2006 Torus Knot Software Ltd
    00008 Also see acknowledgements in Readme.html
    00009
    00010 This program is free software; you can redistribute it and/or modify it under
    00011 the terms of the GNU Lesser General Public License as published by the Free Software
    00012 Foundation; either version 2 of the License, or (at your option) any later
    00013 version.
    00014
    00015 This program is distributed in the hope that it will be useful, but WITHOUT
    00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00018
    00019 You should have received a copy of the GNU Lesser General Public License along with
    00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
    00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
    00022 http://www.gnu.org/copyleft/lesser.txt.
    00023
    00024 You may alternatively use this source under the terms of a specific version of
    00025 the OGRE Unrestricted License provided you have obtained such a license from
    00026 Torus Knot Software Ltd.
    00027 -----------------------------------------------------------------------------
    00028 */
    00029 #ifndef __Exception_H_
    00030 #define __Exception_H_
    00031
    00032 // Precompiler options
    00033 #include "OgrePrerequisites.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 {
    00086     class _OgreExport Exception : public std::exception
    00087     {
    00088     protected:
    00089         long line;
    00090         int number;
    00091         String typeName;
    00092         String description;
    00093         String source;
    00094         String file;
    00095         mutable String fullDesc;
    00096     public:
    00102         enum ExceptionCodes {
    00103             ERR_CANNOT_WRITE_TO_FILE,
    00104             ERR_INVALID_STATE,
    00105             ERR_INVALIDPARAMS,
    00106             ERR_RENDERINGAPI_ERROR,
    00107             ERR_DUPLICATE_ITEM,
    00108             ERR_ITEM_NOT_FOUND,
    00109             ERR_FILE_NOT_FOUND,
    00110             ERR_INTERNAL_ERROR,
    00111             ERR_RT_ASSERTION_FAILED,
    00112             ERR_NOT_IMPLEMENTED
    00113         };
    00114
    00117         Exception( int number, const String& description, const String& source );
    00118
    00121         Exception( int number, const String& description, const String& source, const char* type, const char* file, long line );
    00122
    00125         Exception(const Exception& rhs);
    00126
    00128         ~Exception() throw() {}
    00129
    00132         void operator = (const Exception& rhs);
    00133
    00144         virtual const String& getFullDescription(void) const;
    00145
    00148         virtual int getNumber(void) const throw();
    00149
    00152         virtual const String &getSource() const { return source; }
    00153
    00156         virtual const String &getFile() const { return file; }
    00157
    00160         virtual long getLine() const { return line; }
    00161
    00166         virtual const String &getDescription(void) const { return description; }
    00167
    00169         const char* what() const throw() { return getFullDescription().c_str(); }
    00170
    00171     };
    00172
    00173
    00180     template <int num>
    00181     struct ExceptionCodeType
    00182     {
    00183         enum { number = num };
    00184     };
    00185
    00186     // Specialised exceptions allowing each to be caught specifically
    00187     // backwards-compatible since exception codes still used
    00188
    00189     class _OgreExport UnimplementedException : public Exception
    00190     {
    00191     public:
    00192         UnimplementedException(int number, const String& description, const String& source, const char* file, long line)
    00193             : Exception(number, description, source, "UnimplementedException", file, line) {}
    00194     };
    00195     class _OgreExport FileNotFoundException : public Exception
    00196     {
    00197     public:
    00198         FileNotFoundException(int number, const String& description, const String& source, const char* file, long line)
    00199             : Exception(number, description, source, "FileNotFoundException", file, line) {}
    00200     };
    00201     class _OgreExport IOException : public Exception
    00202     {
    00203     public:
    00204         IOException(int number, const String& description, const String& source, const char* file, long line)
    00205             : Exception(number, description, source, "IOException", file, line) {}
    00206     };
    00207     class _OgreExport InvalidStateException : public Exception
    00208     {
    00209     public:
    00210         InvalidStateException(int number, const String& description, const String& source, const char* file, long line)
    00211             : Exception(number, description, source, "InvalidStateException", file, line) {}
    00212     };
    00213     class _OgreExport InvalidParametersException : public Exception
    00214     {
    00215     public:
    00216         InvalidParametersException(int number, const String& description, const String& source, const char* file, long line)
    00217             : Exception(number, description, source, "InvalidParametersException", file, line) {}
    00218     };
    00219     class _OgreExport ItemIdentityException : public Exception
    00220     {
    00221     public:
    00222         ItemIdentityException(int number, const String& description, const String& source, const char* file, long line)
    00223             : Exception(number, description, source, "ItemIdentityException", file, line) {}
    00224     };
    00225     class _OgreExport InternalErrorException : public Exception
    00226     {
    00227     public:
    00228         InternalErrorException(int number, const String& description, const String& source, const char* file, long line)
    00229             : Exception(number, description, source, "InternalErrorException", file, line) {}
    00230     };
    00231     class _OgreExport RenderingAPIException : public Exception
    00232     {
    00233     public:
    00234         RenderingAPIException(int number, const String& description, const String& source, const char* file, long line)
    00235             : Exception(number, description, source, "RenderingAPIException", file, line) {}
    00236     };
    00237     class _OgreExport RuntimeAssertionException : public Exception
    00238     {
    00239     public:
    00240         RuntimeAssertionException(int number, const String& description, const String& source, const char* file, long line)
    00241             : Exception(number, description, source, "RuntimeAssertionException", file, line) {}
    00242     };
    00243
    00244
    00254     class ExceptionFactory
    00255     {
    00256     private:
    00258         ExceptionFactory() {}
    00259     public:
    00260         static UnimplementedException create(
    00261             ExceptionCodeType<Exception::ERR_NOT_IMPLEMENTED> code,
    00262             const String& desc,
    00263             const String& src, const char* file, long line)
    00264         {
    00265             return UnimplementedException(code.number, desc, src, file, line);
    00266         }
    00267         static FileNotFoundException create(
    00268             ExceptionCodeType<Exception::ERR_FILE_NOT_FOUND> code,
    00269             const String& desc,
    00270             const String& src, const char* file, long line)
    00271         {
    00272             return FileNotFoundException(code.number, desc, src, file, line);
    00273         }
    00274         static IOException create(
    00275             ExceptionCodeType<Exception::ERR_CANNOT_WRITE_TO_FILE> code,
    00276             const String& desc,
    00277             const String& src, const char* file, long line)
    00278         {
    00279             return IOException(code.number, desc, src, file, line);
    00280         }
    00281         static InvalidStateException create(
    00282             ExceptionCodeType<Exception::ERR_INVALID_STATE> code,
    00283             const String& desc,
    00284             const String& src, const char* file, long line)
    00285         {
    00286             return InvalidStateException(code.number, desc, src, file, line);
    00287         }
    00288         static InvalidParametersException create(
    00289             ExceptionCodeType<Exception::ERR_INVALIDPARAMS> code,
    00290             const String& desc,
    00291             const String& src, const char* file, long line)
    00292         {
    00293             return InvalidParametersException(code.number, desc, src, file, line);
    00294         }
    00295         static ItemIdentityException create(
    00296             ExceptionCodeType<Exception::ERR_ITEM_NOT_FOUND> code,
    00297             const String& desc,
    00298             const String& src, const char* file, long line)
    00299         {
    00300             return ItemIdentityException(code.number, desc, src, file, line);
    00301         }
    00302         static ItemIdentityException create(
    00303             ExceptionCodeType<Exception::ERR_DUPLICATE_ITEM> code,
    00304             const String& desc,
    00305             const String& src, const char* file, long line)
    00306         {
    00307             return ItemIdentityException(code.number, desc, src, file, line);
    00308         }
    00309         static InternalErrorException create(
    00310             ExceptionCodeType<Exception::ERR_INTERNAL_ERROR> code,
    00311             const String& desc,
    00312             const String& src, const char* file, long line)
    00313         {
    00314             return InternalErrorException(code.number, desc, src, file, line);
    00315         }
    00316         static RenderingAPIException create(
    00317             ExceptionCodeType<Exception::ERR_RENDERINGAPI_ERROR> code,
    00318             const String& desc,
    00319             const String& src, const char* file, long line)
    00320         {
    00321             return RenderingAPIException(code.number, desc, src, file, line);
    00322         }
    00323         static RuntimeAssertionException create(
    00324             ExceptionCodeType<Exception::ERR_RT_ASSERTION_FAILED> code,
    00325             const String& desc,
    00326             const String& src, const char* file, long line)
    00327         {
    00328             return RuntimeAssertionException(code.number, desc, src, file, line);
    00329         }
    00330
    00331     };
    00332
    00333
    00334
    00335 #ifndef OGRE_EXCEPT
    00336 #define OGRE_EXCEPT(num, desc, src) throw Ogre::ExceptionFactory::create( \
    00337     Ogre::ExceptionCodeType<num>(), desc, src, __FILE__, __LINE__ );
    00338 #endif
    00339
    00340 } // Namespace Ogre
    00341 #endif

Copyright © 2000-2005 by The OGRE Team
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Thu Mar 6 09:46:25 2008