Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

OgreException.cpp

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 © 2000-2002 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 #include "OgreStableHeaders.h"
00026 #include "OgreException.h"
00027 
00028 #include "OgreRoot.h"
00029 #include "OgreLogManager.h"
00030 
00031 #ifdef __BORLANDC__
00032     #include <stdio.h>
00033 #endif
00034 
00035 namespace Ogre {
00036 
00037     Exception* Exception::last = NULL;
00038 
00039     OgreChar Exception::msFunctionStack[ OGRE_CALL_STACK_DEPTH ][ 256 ];
00040     ushort   Exception::msStackDepth = 0;
00041 
00042     Exception::Exception(int num, const String& desc, const String& src) :
00043         line( 0 ),
00044         number( num ),
00045         description( desc ),
00046         source( src ),
00047         stackDepth( msStackDepth )
00048     {
00049         // Log this error - not any more, allow catchers to do it
00050         //LogManager::getSingleton().logMessage(this->getFullDescription());
00051 
00052         // Set last
00053         last = this;
00054     }
00055 
00056     Exception::Exception(int num, const String& desc, const String& src, char* fil, long lin) :
00057         line( lin ),
00058         number( num ),
00059         description( desc ),
00060         source( src ),
00061         file( fil ),
00062         stackDepth( msStackDepth )
00063     {
00064         // Log this error, mask it from debug though since it may be caught and ignored
00065         LogManager::getSingleton().logMessage(this->getFullDescription(), 
00066             LML_CRITICAL, true);
00067 
00068         // Set last
00069         last = this;
00070     }
00071 
00072     Exception::Exception(const Exception& rhs)
00073         : line( rhs.line ), number( rhs.number ), description( rhs.description ), source( rhs.source ), file( rhs.file )
00074     {
00075     }
00076 
00077     void Exception::operator = ( const Exception& rhs )
00078     {
00079         description = rhs.description;
00080         number = rhs.number;
00081         source = rhs.source;
00082         file = rhs.file;
00083         line = rhs.line;
00084     }
00085 
00086     String Exception::getFullDescription(void) const
00087     {
00088         char strNum[12];
00089         String desc;
00090 
00091         sprintf( strNum, "%d", number );
00092         desc =  "An exception has been thrown!\n"
00093                 "\n"
00094                 "-----------------------------------\nDetails:\n-----------------------------------\n"
00095                 "Error #: ";
00096         desc += strNum;
00097         desc += "\nFunction: ";
00098         desc += source;
00099         desc += "\nDescription: ";
00100         desc += description;
00101         desc += ". ";
00102 
00103         if( line > 0 )
00104         {
00105             desc += "\nFile: ";
00106             desc += file;
00107 
00108             char szLine[20];
00109 
00110             desc += "\nLine: ";
00111             snprintf(szLine, 20, "%ld", line);
00112 
00113             desc += szLine;
00114         }
00115 
00116 #ifdef OGRE_STACK_UNWINDING
00117         String funcStack = "\nStack unwinding: ";
00118 
00119         /* Will cause an overflow, that's why we check that it's smaller.
00120            Also note that the call stack index may be greater than the actual call
00121            stack size - that's why we begin unrolling with the smallest of the two. */
00122         for( 
00123             ushort stackUnroll = stackDepth <= OGRE_CALL_STACK_DEPTH ? ( stackDepth - 1 ) : ( OGRE_CALL_STACK_DEPTH - 1 ); 
00124             stackUnroll < stackDepth; stackUnroll-- )
00125         {
00126             funcStack += msFunctionStack[ stackUnroll ];
00127             funcStack += "(..) <- ";
00128         }
00129 
00130         desc += funcStack;
00131         desc += "<<beginning of stack>>";
00132 #endif
00133 
00134         return desc;
00135     }
00136 
00137     int Exception::getNumber(void) const throw()
00138     {
00139         return number;
00140     }
00141 
00142     Exception* Exception::getLastException(void) throw()
00143     {
00144         return last;
00145     }
00146 
00147     //-----------------------------------------------------------------------
00148     void Exception::_pushFunction( const String& strFuncName ) throw()
00149     {
00150         if( msStackDepth < OGRE_CALL_STACK_DEPTH )
00151             strncpy( msFunctionStack[ msStackDepth ], strFuncName.c_str(), 255 );
00152         msStackDepth++;
00153     }
00154 
00155     //-----------------------------------------------------------------------
00156     void Exception::_popFunction() throw()
00157     {
00158         msStackDepth--;
00159     }
00160 }
00161 

Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:24 2004