source: GTP/trunk/App/Demos/Geom/include/OgreException.h @ 1030

Revision 1030, 7.3 KB checked in by gumbau, 18 years ago (diff)

Ogre Stuff initial import

RevLine 
[1030]1/*
2-----------------------------------------------------------------------------
3This source file is part of OGRE
4(Object-oriented Graphics Rendering Engine)
5For the latest info, see http://www.ogre3d.org/
6
7Copyright (c) 2000-2005 The OGRE Team
8Also see acknowledgements in Readme.html
9
10This program is free software; you can redistribute it and/or modify it under
11the terms of the GNU Lesser General Public License as published by the Free Software
12Foundation; either version 2 of the License, or (at your option) any later
13version.
14
15This program is distributed in the hope that it will be useful, but WITHOUT
16ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
17FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
18
19You should have received a copy of the GNU Lesser General Public License along with
20this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21Place - Suite 330, Boston, MA 02111-1307, USA, or go to
22http://www.gnu.org/copyleft/lesser.txt.
23-----------------------------------------------------------------------------
24*/
25#ifndef __Exception_H_
26#define __Exception_H_
27
28// Precompiler options
29#include "OgrePrerequisites.h"
30
31#include "OgreString.h"
32
33#define OGRE_EXCEPT( num, desc, src ) throw( Ogre::Exception( num, desc, src, __FILE__, __LINE__ ) )
34
35// Stack unwinding options
36// OgreUnguard and OgreUnguardRet are deprecated
37#if OGRE_STACK_UNWINDING == 1
38#   if OGRE_COMPILER != OGRE_COMPILER_BORL
39#       define OgreGuard( a ) Ogre::AutomaticGuardUnguard _auto_guard_object( (a) )
40#   else
41#       define OgreGuard( a ) Ogre::AutomaticGuardUnguard _auto_guard_object( __FUNC__ )
42#   endif
43
44#   define OgreUnguard()
45#   define OgreUnguardRet( a ) return a
46
47#else
48#   define OgreGuard( a )
49#   define OgreUnguard()
50#   define OgreUnguardRet( a ) return a
51
52#endif
53
54// Backwards compatibility with old assert mode definitions
55#if OGRE_RELEASE_ASSERT == 1
56#   define OGRE_ASSERT_MODE 1
57#endif
58
59// Check for OGRE assert mode
60
61// RELEASE_EXCEPTIONS mode
62#if OGRE_ASSERT_MODE == 1
63#   ifdef _DEBUG
64#       define OgreAssert( a, b ) assert( (a) && (b) )
65
66#   else
67#       if OGRE_COMP != OGRE_COMPILER_BORL
68#           define OgreAssert( a, b ) if( !(a) ) OGRE_EXCEPT( Ogre::Exception::ERR_RT_ASSERTION_FAILED, (b), "no function info")
69#       else
70#           define OgreAssert( a, b ) if( !(a) ) OGRE_EXCEPT( Ogre::Exception::ERR_RT_ASSERTION_FAILED, (b), __FUNC__ )
71#       endif
72
73#   endif
74
75// EXCEPTIONS mode
76#elif OGRE_ASSERT_MODE == 2
77#   if OGRE_COMP != OGRE_COMPILER_BORL
78#       define OgreAssert( a, b ) if( !(a) ) OGRE_EXCEPT( Ogre::Exception::ERR_RT_ASSERTION_FAILED, (b), "no function info")
79#   else
80#       define OgreAssert( a, b ) if( !(a) ) OGRE_EXCEPT( Ogre::Exception::ERR_RT_ASSERTION_FAILED, (b), __FUNC__ )
81#   endif
82
83// STANDARD mode
84#else
85#   define OgreAssert( a, b ) assert( (a) && (b) )
86
87#endif
88
89#define OGRE_CALL_STACK_DEPTH 512
90
91namespace Ogre {
92    /** When thrown, provides information about an error that has occurred inside the engine.
93        @remarks
94            OGRE never uses return values to indicate errors. Instead, if an
95            error occurs, an exception is thrown, and this is the object that
96            encapsulates the detail of the problem. The application using
97            OGRE should always ensure that the exceptions are caught, so all
98            OGRE engine functions should occur within a
99            try{} catch(Ogre::Exception& e) {} block.
100        @par
101            The user application should never create any instances of this
102            object unless it wishes to unify its error handling using the
103            same object.
104    */
105    class _OgreExport Exception
106    {
107    protected:
108        long line;
109        int number;
110        String description;
111        String source;
112        String file;
113        ushort stackDepth;
114        static Exception* last;
115
116        static String msFunctionStack[ OGRE_CALL_STACK_DEPTH ];
117        static ushort   msStackDepth;
118    public:
119        /** Static definitions of error codes.
120            @todo
121                Add many more exception codes, since we want the user to be able
122                to catch most of them.
123        */
124        enum ExceptionCodes {
125            UNIMPLEMENTED_FEATURE,
126            ERR_CANNOT_WRITE_TO_FILE,
127            ERR_NO_RENDERSYSTEM_SELECTED,
128            ERR_DIALOG_OPEN_ERROR,
129            ERR_INVALIDPARAMS,
130            ERR_RENDERINGAPI_ERROR,
131            ERR_DUPLICATE_ITEM,
132            ERR_ITEM_NOT_FOUND,
133            ERR_FILE_NOT_FOUND,
134            ERR_INTERNAL_ERROR,
135            ERR_RT_ASSERTION_FAILED
136        };
137
138        /** Default constructor.
139        */
140        Exception( int number, const String& description, const String& source );
141
142        /** Advanced constructor.
143        */
144        Exception( int number, const String& description, const String& source, char* file, long line );
145
146        /** Copy constructor.
147        */
148        Exception(const Exception& rhs);
149
150        /** Assignment operator.
151        */
152        void operator = (const Exception& rhs);
153
154        /** Returns a string with the full description of this error.
155            @remarks
156                The description contains the error number, the description
157                supplied by the thrower, what routine threw the exception,
158                and will also supply extra platform-specific information
159                where applicable. For example - in the case of a rendering
160                library error, the description of the error will include both
161                the place in which OGRE found the problem, and a text
162                description from the 3D rendering library, if available.
163        */
164        String getFullDescription(void) const;
165
166        /** Gets the error code.
167        */
168        int getNumber(void) const throw();
169
170        /** Gets the source function.
171        */
172        const String &getSource() const { return source; }
173
174        /** Gets source file name.
175        */
176        const String &getFile() const { return file; }
177
178        /** Gets line number.
179        */
180        long getLine() const { return line; }
181
182                /** Returns a string with only the 'description' field of this exception. Use
183                        getFullDescriptionto get a full description of the error including line number,
184                        error number and what function threw the exception.
185        */
186                const String &getDescription(void) const { return description; }
187
188        /** Retrieves a pointer to the last exception created.
189        */
190        static Exception* getLastException(void) throw();
191
192        /** Pushes a function on the stack.
193        */
194        static void _pushFunction( const String& strFuncName ) throw();
195        /** Pops a function from the stack.
196        */
197        static void _popFunction() throw();
198
199       
200    };
201
202    /** Internal class. Objects will automatically push/pop the function name for unwinding. */
203    class _OgreExport AutomaticGuardUnguard {
204    public:
205        AutomaticGuardUnguard(const String& funcName) throw()
206        {
207            Exception::_pushFunction(funcName);
208        }
209        ~AutomaticGuardUnguard() throw()
210        {
211            Exception::_popFunction();
212        }
213    };
214
215} // Namespace Ogre
216#endif
Note: See TracBrowser for help on using the repository browser.