Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | 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-2005 The OGRE Team
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 */
00025 #ifndef __Exception_H_
00026 #define __Exception_H_
00027 
00028 // Precompiler options
00029 #include "OgrePrerequisites.h"
00030 
00031 #include "OgreString.h"
00032 
00033 #define OGRE_EXCEPT( num, desc, src ) throw( Ogre::Exception( num, desc, src, __FILE__, __LINE__ ) )
00034 
00035 // Stack unwinding options
00036 // OgreUnguard and OgreUnguardRet are deprecated
00037 #if OGRE_STACK_UNWINDING == 1
00038 #   if OGRE_COMPILER != OGRE_COMPILER_BORL
00039 #       define OgreGuard( a ) Ogre::AutomaticGuardUnguard _auto_guard_object( (a) )
00040 #   else
00041 #       define OgreGuard( a ) Ogre::AutomaticGuardUnguard _auto_guard_object( __FUNC__ )
00042 #   endif
00043 
00044 #   define OgreUnguard() 
00045 #   define OgreUnguardRet( a ) return a
00046 
00047 #else
00048 #   define OgreGuard( a )
00049 #   define OgreUnguard()
00050 #   define OgreUnguardRet( a ) return a
00051 
00052 #endif
00053 
00054 // Backwards compatibility with old assert mode definitions
00055 #if OGRE_RELEASE_ASSERT == 1
00056 #   define OGRE_ASSERT_MODE 1
00057 #endif
00058 
00059 // Check for OGRE assert mode
00060 
00061 // RELEASE_EXCEPTIONS mode
00062 #if OGRE_ASSERT_MODE == 1
00063 #   ifdef _DEBUG
00064 #       define OgreAssert( a, b ) assert( (a) && (b) )
00065 
00066 #   else
00067 #       if OGRE_COMP != OGRE_COMPILER_BORL
00068 #           define OgreAssert( a, b ) if( !(a) ) OGRE_EXCEPT( Ogre::Exception::ERR_RT_ASSERTION_FAILED, (b), "no function info")
00069 #       else
00070 #           define OgreAssert( a, b ) if( !(a) ) OGRE_EXCEPT( Ogre::Exception::ERR_RT_ASSERTION_FAILED, (b), __FUNC__ )
00071 #       endif
00072 
00073 #   endif
00074 
00075 // EXCEPTIONS mode
00076 #elif OGRE_ASSERT_MODE == 2
00077 #   if OGRE_COMP != OGRE_COMPILER_BORL
00078 #       define OgreAssert( a, b ) if( !(a) ) OGRE_EXCEPT( Ogre::Exception::ERR_RT_ASSERTION_FAILED, (b), "no function info")
00079 #   else
00080 #       define OgreAssert( a, b ) if( !(a) ) OGRE_EXCEPT( Ogre::Exception::ERR_RT_ASSERTION_FAILED, (b), __FUNC__ )
00081 #   endif
00082 
00083 // STANDARD mode
00084 #else
00085 #   define OgreAssert( a, b ) assert( (a) && (b) )
00086 
00087 #endif
00088 
00089 #define OGRE_CALL_STACK_DEPTH 512
00090 
00091 namespace Ogre {
00105     class _OgreExport Exception
00106     {
00107     protected:
00108         long line;
00109         int number;
00110         String description;
00111         String source;
00112         String file;
00113         ushort stackDepth;
00114         static Exception* last;
00115 
00116         static String msFunctionStack[ OGRE_CALL_STACK_DEPTH ];
00117         static ushort   msStackDepth;
00118     public:
00124         enum ExceptionCodes {
00125             UNIMPLEMENTED_FEATURE,
00126             ERR_CANNOT_WRITE_TO_FILE,
00127             ERR_NO_RENDERSYSTEM_SELECTED,
00128             ERR_DIALOG_OPEN_ERROR,
00129             ERR_INVALIDPARAMS,
00130             ERR_RENDERINGAPI_ERROR,
00131             ERR_DUPLICATE_ITEM,
00132             ERR_ITEM_NOT_FOUND,
00133             ERR_FILE_NOT_FOUND,
00134             ERR_INTERNAL_ERROR,
00135             ERR_RT_ASSERTION_FAILED, 
00136             ERR_NOT_IMPLEMENTED
00137         };
00138 
00141         Exception( int number, const String& description, const String& source );
00142 
00145         Exception( int number, const String& description, const String& source, char* file, long line );
00146 
00149         Exception(const Exception& rhs);
00150 
00153         void operator = (const Exception& rhs);
00154 
00165         String getFullDescription(void) const;
00166 
00169         int getNumber(void) const throw();
00170 
00173         const String &getSource() const { return source; }
00174 
00177         const String &getFile() const { return file; }
00178 
00181         long getLine() const { return line; }
00182 
00187         const String &getDescription(void) const { return description; }
00188 
00191         static Exception* getLastException(void) throw();
00192 
00195         static void _pushFunction( const String& strFuncName ) throw();
00198         static void _popFunction() throw();
00199 
00200         
00201     };
00202 
00204     class _OgreExport AutomaticGuardUnguard {
00205     public:
00206         AutomaticGuardUnguard(const String& funcName) throw()
00207         {
00208             Exception::_pushFunction(funcName);
00209         }
00210         ~AutomaticGuardUnguard() throw()
00211         {
00212             Exception::_popFunction();
00213         }
00214     };
00215 
00216 } // Namespace Ogre
00217 #endif

Copyright © 2000-2005 by The OGRE Team
Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 2.5 License.
Last modified Sun Mar 12 14:37:40 2006