// exception standard header for Microsoft #pragma once #ifndef _EXCEPTION_ #define _EXCEPTION_ #include #pragma pack(push,8) #pragma warning(push,3) #include #if !defined(_WIN32) #error ERROR: Only Win32 targets supported! #endif #ifndef _CRTIMP #ifdef _DLL #define _CRTIMP __declspec(dllimport) #else /* ndef _DLL */ #define _CRTIMP #endif /* _DLL */ #endif /* _CRTIMP */ typedef const char *__exString; class _CRTIMP exception { // base of all library exceptions public: exception(); exception(const char *const&); exception(const exception&); exception& operator=(const exception&); virtual ~exception(); virtual const char *what() const; private: const char *_m_what; int _m_doFree; }; _STD_BEGIN #if _HAS_EXCEPTIONS using ::exception; typedef void (*_Prhand)(const exception&); extern _CRTIMP2 _Prhand _Raise_handler; _CRTIMP2 bool __cdecl uncaught_exception(); using ::unexpected_handler; using ::set_unexpected; using ::unexpected; using ::terminate_handler; using ::set_terminate; using ::terminate; #else /* _HAS_EXCEPTIONS */ // CLASS exception class exception; typedef void (*_Prhand)(const exception&); extern _CRTIMP2 _Prhand _Raise_handler; // pointer to raise handler _CRTIMP2 void __cdecl _Throw(const exception&); // throw the exception class _CRTIMP2 exception { // base of all library exceptions public: static _Prhand _Set_raise_handler(_Prhand _Pnew) { // register a handler for _Raise calls const _Prhand _Pold = _Raise_handler; _Raise_handler = _Pnew; return (_Pold); } explicit exception(const char *_Message = _MESG("unknown")) _THROW0() : _Ptr(_Message) { // construct from message string } exception(const exception& _Right) _THROW0() : _Ptr(_Right._Ptr) { // construct by copying _Right } exception& operator=(const exception& _Right) _THROW0() { // assign _Right _Ptr = _Right._Ptr; return (*this); } virtual ~exception() { // destroy the object } virtual const char *what() const _THROW0() { // return pointer to message string return (_Ptr); } void _Raise() const { // raise the exception if (_Raise_handler != 0) (*_Raise_handler)(*this); // call raise handler if present _Doraise(); // call the protected virtual _RAISE(*this); // raise this exception } protected: virtual void _Doraise() const { // perform class-specific exception handling } const char *_Ptr; // the message pointer }; // TYPES typedef void (__cdecl *terminate_handler)(); typedef void (__cdecl *unexpected_handler)(); // DUMMY FUNCTION DECLARATIONS inline terminate_handler __cdecl set_terminate(terminate_handler) _THROW0() { // register a terminate handler return 0; } inline unexpected_handler __cdecl set_unexpected(unexpected_handler) _THROW0() { // register an unexpected handler return 0; } inline void __cdecl terminate() { // handle exception termination } inline void __cdecl unexpected() { // handle unexpected exception } _CRTIMP2 bool __cdecl uncaught_exception(); // handle uncaught exception #endif /* _HAS_EXCEPTIONS */ // CLASS bad_exception class bad_exception : public exception { // base of all bad exceptions public: bad_exception(const char *_Message = _MESG("bad exception")) _THROW0() : exception(_Message) { // construct from message string } virtual ~bad_exception() _THROW0() { // destroy the object } #if !_HAS_EXCEPTIONS protected: virtual void _Doraise() const { // raise this exception _RAISE(*this); } #endif /* _HAS_EXCEPTIONS */ }; _STD_END #pragma warning(pop) #pragma pack(pop) #endif /* _EXCEPTION_ */ /* * Copyright (c) 1992-2001 by P.J. Plauger. ALL RIGHTS RESERVED. * Consult your license regarding permissions and restrictions. V3.10:0009 */