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 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 00065 LogManager::getSingleton().logMessage(this->getFullDescription()); 00066 00067 // Set last 00068 last = this; 00069 } 00070 00071 Exception::Exception(const Exception& rhs) 00072 : line( rhs.line ), number( rhs.number ), description( rhs.description ), source( rhs.source ), file( rhs.file ) 00073 { 00074 } 00075 00076 void Exception::operator = ( const Exception& rhs ) 00077 { 00078 description = rhs.description; 00079 number = rhs.number; 00080 source = rhs.source; 00081 file = rhs.file; 00082 line = rhs.line; 00083 } 00084 00085 String Exception::getFullDescription(void) const 00086 { 00087 char strNum[12]; 00088 String desc; 00089 00090 sprintf( strNum, "%d", number ); 00091 desc = "An exception has been thrown!\n" 00092 "\n" 00093 "-----------------------------------\nDetails:\n-----------------------------------\n" 00094 "Error #: "; 00095 desc += strNum; 00096 desc += "\nFunction: "; 00097 desc += source; 00098 desc += "\nDescription: "; 00099 desc += description; 00100 desc += ". "; 00101 00102 if( line > 0 ) 00103 { 00104 desc += "\nFile: "; 00105 desc += file; 00106 00107 char szLine[20]; 00108 00109 desc += "\nLine: "; 00110 snprintf(szLine, 20, "%ld", line); 00111 00112 desc += szLine; 00113 } 00114 00115 #ifdef OGRE_STACK_UNWINDING 00116 String funcStack = "\nStack unwinding: "; 00117 00118 /* Will cause an overflow, that's why we check that it's smaller. 00119 Also note that the call stack index may be greater than the actual call 00120 stack size - that's why we begin unrolling with the smallest of the two. */ 00121 for( 00122 ushort stackUnroll = stackDepth <= OGRE_CALL_STACK_DEPTH ? ( stackDepth - 1 ) : ( OGRE_CALL_STACK_DEPTH - 1 ); 00123 stackUnroll < stackDepth; stackUnroll-- ) 00124 { 00125 funcStack += msFunctionStack[ stackUnroll ]; 00126 funcStack += "(..) <- "; 00127 } 00128 00129 desc += funcStack; 00130 desc += "<<beginning of stack>>"; 00131 #endif 00132 00133 return desc; 00134 } 00135 00136 int Exception::getNumber(void) const throw() 00137 { 00138 return number; 00139 } 00140 00141 Exception* Exception::getLastException(void) throw() 00142 { 00143 return last; 00144 } 00145 00146 //----------------------------------------------------------------------- 00147 void Exception::_pushFunction( const String& strFuncName ) throw() 00148 { 00149 if( msStackDepth < OGRE_CALL_STACK_DEPTH ) 00150 strncpy( msFunctionStack[ msStackDepth ], strFuncName.c_str(), 255 ); 00151 msStackDepth++; 00152 } 00153 00154 //----------------------------------------------------------------------- 00155 void Exception::_popFunction() throw() 00156 { 00157 msStackDepth--; 00158 } 00159 } 00160
Copyright © 2002-2003 by The OGRE Team
Last modified Wed Jan 21 00:10:10 2004