00001 /* ///////////////////////////////////////////////////////////////////////// 00002 * File: stlsoft/error/unrecoverable.hpp 00003 * 00004 * Purpose: Definition of the \c unrecoverable exception class. 00005 * 00006 * Created: 14th October 2004 00007 * Updated: 10th August 2009 00008 * 00009 * Home: http://stlsoft.org/ 00010 * 00011 * Copyright (c) 2004-2009, Matthew Wilson and Synesis Software 00012 * All rights reserved. 00013 * 00014 * Redistribution and use in source and binary forms, with or without 00015 * modification, are permitted provided that the following conditions are met: 00016 * 00017 * - Redistributions of source code must retain the above copyright notice, this 00018 * list of conditions and the following disclaimer. 00019 * - Redistributions in binary form must reproduce the above copyright notice, 00020 * this list of conditions and the following disclaimer in the documentation 00021 * and/or other materials provided with the distribution. 00022 * - Neither the name(s) of Matthew Wilson and Synesis Software nor the names of 00023 * any contributors may be used to endorse or promote products derived from 00024 * this software without specific prior written permission. 00025 * 00026 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00027 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00028 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00029 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00030 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00031 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00032 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00033 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00034 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00035 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00036 * POSSIBILITY OF SUCH DAMAGE. 00037 * 00038 * ////////////////////////////////////////////////////////////////////// */ 00039 00040 00048 #ifndef STLSOFT_INCL_STLSOFT_ERROR_HPP_UNRECOVERABLE 00049 #define STLSOFT_INCL_STLSOFT_ERROR_HPP_UNRECOVERABLE 00050 00051 #ifndef STLSOFT_DOCUMENTATION_SKIP_SECTION 00052 # define STLSOFT_VER_STLSOFT_ERROR_HPP_UNRECOVERABLE_MAJOR 2 00053 # define STLSOFT_VER_STLSOFT_ERROR_HPP_UNRECOVERABLE_MINOR 0 00054 # define STLSOFT_VER_STLSOFT_ERROR_HPP_UNRECOVERABLE_REVISION 2 00055 # define STLSOFT_VER_STLSOFT_ERROR_HPP_UNRECOVERABLE_EDIT 29 00056 #endif /* !STLSOFT_DOCUMENTATION_SKIP_SECTION */ 00057 00058 /* ///////////////////////////////////////////////////////////////////////// 00059 * Includes 00060 */ 00061 00062 #ifndef STLSOFT_INCL_STLSOFT_H_STLSOFT 00063 # include <stlsoft/stlsoft.h> 00064 #endif /* !STLSOFT_INCL_STLSOFT_H_STLSOFT */ 00065 #ifdef STLSOFT_CF_std_NAMESPACE 00066 # include <exception> 00067 #else /* ? STLSOFT_CF_std_NAMESPACE */ 00068 # if defined(STLSOFT_COMPILER_IS_WATCOM) 00069 # include <except.h> // for terminate() 00070 # include <stdexcep.h> // for 'std' exceptions 00071 # else /* ? compiler */ 00072 # error No other non-std compiler supported 00073 # endif /* compiler */ 00074 #endif /* STLSOFT_CF_std_NAMESPACE */ 00075 #if defined(STLSOFT_UNRECOVERABLE_EXCEPTION_USE_WIN32_EXITPROCESS) || \ 00076 defined(STLSOFT_COMPILER_IS_MWERKS) 00077 # include <stdlib.h> // for EXIT_FAILURE / exit() 00078 #endif /* compiler */ 00079 #if defined(STLSOFT_UNRECOVERABLE_EXCEPTION_USE_WIN32_EXITPROCESS) 00080 # include <windows.h> // for ExitProcess() 00081 #endif /* STLSOFT_UNRECOVERABLE_EXCEPTION_USE_WIN32_EXITPROCESS */ 00082 00083 /* ///////////////////////////////////////////////////////////////////////// 00084 * Namespace 00085 */ 00086 00087 #ifndef _STLSOFT_NO_NAMESPACE 00088 namespace stlsoft 00089 { 00090 #endif /* _STLSOFT_NO_NAMESPACE */ 00091 00092 /* ///////////////////////////////////////////////////////////////////////// 00093 * Classes 00094 */ 00095 00103 class unrecoverable 00104 : public stlsoft_ns_qual_std(exception) 00105 { 00108 public: 00110 typedef stlsoft_ns_qual_std(exception) parent_class_type; 00112 typedef unrecoverable class_type; 00114 00117 protected: 00119 ss_explicit_k unrecoverable(void (*pfnHandler)() = NULL) 00120 : m_refcnt(new long(1)) 00121 , m_pfnHandler(pfnHandler) 00122 {} 00123 public: 00128 unrecoverable(class_type const& rhs) 00129 : m_refcnt(rhs.m_refcnt) 00130 , m_pfnHandler(rhs.m_pfnHandler) 00131 { 00132 ++*m_refcnt; 00133 } 00138 virtual ~unrecoverable() stlsoft_throw_0() 00139 { 00140 if(0 == --*m_refcnt) 00141 { 00142 delete m_refcnt; // We could forgo this, but might as well be clean 00143 00144 // Invoke the supplied handler 00145 if(NULL != m_pfnHandler) 00146 { 00147 (*m_pfnHandler)(); 00148 } 00149 00150 // If no handler was supplied, or it didn't close the process, we 00151 // call terminate to make sure. Terminate is chosen since it often 00152 // results in an "uglier" closedown than exit(), and that's a good 00153 // thing for unrecoverable exceptions 00154 #if defined(STLSOFT_UNRECOVERABLE_EXCEPTION_USE_WIN32_EXITPROCESS) 00155 ::ExitProcess(EXIT_FAILURE); 00156 #else /* ? STLSOFT_UNRECOVERABLE_EXCEPTION_USE_WIN32_EXITPROCESS */ 00157 # if defined(STLSOFT_COMPILER_IS_MWERKS) 00158 exit(EXIT_FAILURE); 00159 # else /* ? compiler */ 00160 { // Because many compilers (including Borland, DMC++, GCC, etc.) place 00161 // terminate() within std, we introduce a block here, and 'use' the 00162 // std namespace. (Not a thing one normally does, you understand.) 00163 # ifdef STLSOFT_CF_std_NAMESPACE 00164 using namespace ::std; 00165 # endif /* !STLSOFT_CF_std_NAMESPACE */ 00166 00167 terminate(); 00168 } 00169 # endif /* compiler */ 00170 #endif /* STLSOFT_UNRECOVERABLE_EXCEPTION_USE_WIN32_EXITPROCESS */ 00171 } 00172 } 00174 00177 public: 00179 virtual char const* what() const throw() 00180 { 00181 return "unrecoverable condition"; 00182 } 00184 00187 private: 00188 long *const m_refcnt; 00189 void (*m_pfnHandler)(); 00191 00192 // Not to be implemented 00193 private: 00194 class_type& operator =(class_type const&); 00195 00196 void *operator new(ss_size_t ); 00197 }; 00198 00199 /* ////////////////////////////////////////////////////////////////////// */ 00200 00201 #ifndef _STLSOFT_NO_NAMESPACE 00202 } // namespace stlsoft 00203 #endif /* _STLSOFT_NO_NAMESPACE */ 00204 00205 /* ////////////////////////////////////////////////////////////////////// */ 00206 00207 #endif /* !STLSOFT_INCL_STLSOFT_ERROR_HPP_UNRECOVERABLE */ 00208 00209 /* ///////////////////////////// end of file //////////////////////////// */