Whole document tree eh_catch.ccGo to the documentation of this file.00001 // -*- C++ -*- Exception handling routines for catching. 00002 // Copyright (C) 2001 Free Software Foundation, Inc. 00003 // 00004 // This file is part of GNU CC. 00005 // 00006 // GNU CC is free software; you can redistribute it and/or modify 00007 // it under the terms of the GNU General Public License as published by 00008 // the Free Software Foundation; either version 2, or (at your option) 00009 // any later version. 00010 // 00011 // GNU CC is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 // 00016 // You should have received a copy of the GNU General Public License 00017 // along with GNU CC; see the file COPYING. If not, write to 00018 // the Free Software Foundation, 59 Temple Place - Suite 330, 00019 // Boston, MA 02111-1307, USA. 00020 00021 // As a special exception, you may use this file as part of a free software 00022 // library without restriction. Specifically, if other files instantiate 00023 // templates or use macros or inline functions from this file, or you compile 00024 // this file and link it with other files to produce an executable, this 00025 // file does not by itself cause the resulting executable to be covered by 00026 // the GNU General Public License. This exception does not however 00027 // invalidate any other reasons why the executable file might be covered by 00028 // the GNU General Public License. 00029 00030 00031 #include <cstdlib> 00032 #include "unwind-cxx.h" 00033 00034 using namespace __cxxabiv1; 00035 00036 00037 extern "C" void * 00038 __cxa_begin_catch (_Unwind_Exception *exceptionObject) 00039 { 00040 // ??? Foreign exceptions can't be stacked here, and there doesn't 00041 // appear to be any place to store for __cxa_end_catch to destroy. 00042 00043 __cxa_exception *header = __get_exception_header_from_ue (exceptionObject); 00044 __cxa_eh_globals *globals = __cxa_get_globals (); 00045 __cxa_exception *prev = globals->caughtExceptions; 00046 int count = header->handlerCount; 00047 00048 if (count < 0) 00049 // This exception was rethrown from an immediately enclosing region. 00050 count = -count + 1; 00051 else 00052 count += 1; 00053 header->handlerCount = count; 00054 00055 globals->uncaughtExceptions -= 1; 00056 if (header != prev) 00057 { 00058 header->nextException = prev; 00059 globals->caughtExceptions = header; 00060 } 00061 00062 return header->adjustedPtr; 00063 } 00064 00065 00066 extern "C" void 00067 __cxa_end_catch () 00068 { 00069 __cxa_eh_globals *globals = __cxa_get_globals_fast (); 00070 __cxa_exception *header = globals->caughtExceptions; 00071 int count = header->handlerCount; 00072 00073 if (count < 0) 00074 { 00075 // This exception was rethrown. Decrement the (inverted) catch 00076 // count and remove it from the chain when it reaches zero. 00077 if (++count == 0) 00078 { 00079 globals->uncaughtExceptions += 1; 00080 globals->caughtExceptions = header->nextException; 00081 } 00082 } 00083 else if (--count == 0) 00084 { 00085 // Handling for this exception is complete. Destroy the object. 00086 globals->caughtExceptions = header->nextException; 00087 _Unwind_DeleteException (&header->unwindHeader); 00088 return; 00089 } 00090 else if (count < 0) 00091 // A bug in the exception handling library or compiler. 00092 std::abort (); 00093 00094 header->handlerCount = count; 00095 } 00096 00097 00098 bool 00099 std::uncaught_exception() throw() 00100 { 00101 __cxa_eh_globals *globals = __cxa_get_globals (); 00102 return globals->uncaughtExceptions != 0; 00103 } Generated on Mon Apr 8 03:11:24 2002 for libstdc++-v3 Source by ![]() |