source: OGRE/trunk/ogrenew/OgreMain/src/OgreException.cpp @ 657

Revision 657, 4.7 KB checked in by mattausch, 19 years ago (diff)

added ogre dependencies and patched ogre sources

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#include "OgreStableHeaders.h"
26#include "OgreException.h"
27
28#include "OgreRoot.h"
29#include "OgreLogManager.h"
30
31#ifdef __BORLANDC__
32    #include <stdio.h>
33#endif
34
35namespace Ogre {
36
37    Exception* Exception::last = NULL;
38
39    String Exception::msFunctionStack[ OGRE_CALL_STACK_DEPTH ];
40    ushort   Exception::msStackDepth = 0;
41
42    Exception::Exception(int num, const String& desc, const String& src) :
43        line( 0 ),
44        number( num ),
45        description( desc ),
46        source( src ),
47        stackDepth( msStackDepth )
48    {
49        // Log this error - not any more, allow catchers to do it
50        //LogManager::getSingleton().logMessage(this->getFullDescription());
51
52        // Set last
53        last = this;
54    }
55
56    Exception::Exception(int num, const String& desc, const String& src, char* fil, long lin) :
57        line( lin ),
58        number( num ),
59        description( desc ),
60        source( src ),
61        file( fil ),
62        stackDepth( msStackDepth )
63    {
64        // Log this error, mask it from debug though since it may be caught and ignored
65        if(LogManager::getSingletonPtr())
66            LogManager::getSingleton().logMessage(this->getFullDescription(),
67                LML_CRITICAL, true);
68
69        // Set last
70        last = this;
71    }
72
73    Exception::Exception(const Exception& rhs)
74        : line( rhs.line ), number( rhs.number ), description( rhs.description ), source( rhs.source ), file( rhs.file )
75    {
76    }
77
78    void Exception::operator = ( const Exception& rhs )
79    {
80        description = rhs.description;
81        number = rhs.number;
82        source = rhs.source;
83        file = rhs.file;
84        line = rhs.line;
85    }
86
87    String Exception::getFullDescription(void) const
88    {
89                StringUtil::StrStreamType desc;
90
91        desc <<  "An exception has been thrown!\n"
92                "\n"
93                "-----------------------------------\nDetails:\n-----------------------------------\n"
94                "Error #: " << number
95                        << "\nFunction: " << source
96                        << "\nDescription: " << description
97                        << ". ";
98
99        if( line > 0 )
100        {
101            desc << "\nFile: " << file;
102            desc << "\nLine: " << line;
103        }
104
105#ifdef OGRE_STACK_UNWINDING
106        desc << "\nStack unwinding: ";
107
108        /* Will cause an overflow, that's why we check that it's smaller.
109           Also note that the call stack index may be greater than the actual call
110           stack size - that's why we begin unrolling with the smallest of the two. */
111        for(
112            ushort stackUnroll = stackDepth <= OGRE_CALL_STACK_DEPTH ? ( stackDepth - 1 ) : ( OGRE_CALL_STACK_DEPTH - 1 );
113            stackUnroll < stackDepth; stackUnroll-- )
114        {
115            desc << msFunctionStack[ stackUnroll ];
116            desc << "(..) <- ";
117        }
118
119        desc << "<<beginning of stack>>";
120#endif
121
122        return desc.str();
123    }
124
125    int Exception::getNumber(void) const throw()
126    {
127        return number;
128    }
129
130    Exception* Exception::getLastException(void) throw()
131    {
132        return last;
133    }
134
135    //-----------------------------------------------------------------------
136    void Exception::_pushFunction( const String& strFuncName ) throw()
137    {
138        if( msStackDepth < OGRE_CALL_STACK_DEPTH )
139            msFunctionStack[ msStackDepth ] = strFuncName;
140        msStackDepth++;
141    }
142
143    //-----------------------------------------------------------------------
144    void Exception::_popFunction() throw()
145    {
146        msStackDepth--;
147    }
148}
149
Note: See TracBrowser for help on using the repository browser.