source: OGRE/trunk/ogrenew/OgreMain/include/OgreException.h @ 692

Revision 692, 7.3 KB checked in by mattausch, 19 years ago (diff)

adding ogre 1.2 and dependencies

Line 
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                        ERR_NOT_IMPLEMENTED
137        };
138
139        /** Default constructor.
140        */
141        Exception( int number, const String& description, const String& source );
142
143        /** Advanced constructor.
144        */
145        Exception( int number, const String& description, const String& source, char* file, long line );
146
147        /** Copy constructor.
148        */
149        Exception(const Exception& rhs);
150
151        /** Assignment operator.
152        */
153        void operator = (const Exception& rhs);
154
155        /** Returns a string with the full description of this error.
156            @remarks
157                The description contains the error number, the description
158                supplied by the thrower, what routine threw the exception,
159                and will also supply extra platform-specific information
160                where applicable. For example - in the case of a rendering
161                library error, the description of the error will include both
162                the place in which OGRE found the problem, and a text
163                description from the 3D rendering library, if available.
164        */
165        String getFullDescription(void) const;
166
167        /** Gets the error code.
168        */
169        int getNumber(void) const throw();
170
171        /** Gets the source function.
172        */
173        const String &getSource() const { return source; }
174
175        /** Gets source file name.
176        */
177        const String &getFile() const { return file; }
178
179        /** Gets line number.
180        */
181        long getLine() const { return line; }
182
183                /** Returns a string with only the 'description' field of this exception. Use
184                        getFullDescriptionto get a full description of the error including line number,
185                        error number and what function threw the exception.
186        */
187                const String &getDescription(void) const { return description; }
188
189        /** Retrieves a pointer to the last exception created.
190        */
191        static Exception* getLastException(void) throw();
192
193        /** Pushes a function on the stack.
194        */
195        static void _pushFunction( const String& strFuncName ) throw();
196        /** Pops a function from the stack.
197        */
198        static void _popFunction() throw();
199
200       
201    };
202
203    /** Internal class. Objects will automatically push/pop the function name for unwinding. */
204    class _OgreExport AutomaticGuardUnguard {
205    public:
206        AutomaticGuardUnguard(const String& funcName) throw()
207        {
208            Exception::_pushFunction(funcName);
209        }
210        ~AutomaticGuardUnguard() throw()
211        {
212            Exception::_popFunction();
213        }
214    };
215
216} // Namespace Ogre
217#endif
Note: See TracBrowser for help on using the repository browser.