- // stdexcept standard header
- #if _MSC_VER > 1000
- #pragma once
- #endif
- #ifndef _STDEXCEPT_
- #define _STDEXCEPT_
- #include <exception>
- #include <xstring>
- #ifdef _MSC_VER
- #pragma pack(push,8)
- #endif /* _MSC_VER */
- _STD_BEGIN
- // CLASS logic_error
- class _CRTIMP logic_error : public exception {
- public:
- explicit logic_error(const string& _S)
- : exception(""), _Str(_S) {}
- virtual ~logic_error()
- {}
- virtual const char *what() const
- {return (_Str.c_str()); }
- protected:
- virtual void _Doraise() const
- {_RAISE(*this); }
- private:
- string _Str;
- };
- // CLASS domain_error
- class _CRTIMP domain_error : public logic_error {
- public:
- explicit domain_error(const string& _S)
- : logic_error(_S) {}
- virtual ~domain_error()
- {}
- protected:
- virtual void _Doraise() const
- {_RAISE(*this); }
- };
- // CLASS invalid_argument
- class invalid_argument : public logic_error {
- public:
- explicit invalid_argument(const string& _S)
- : logic_error(_S) {}
- virtual ~invalid_argument()
- {}
- protected:
- virtual void _Doraise() const
- {_RAISE(*this); }
- };
- // CLASS length_error
- class _CRTIMP length_error : public logic_error {
- public:
- explicit length_error(const string& _S)
- : logic_error(_S) {}
- virtual ~length_error()
- {}
- protected:
- virtual void _Doraise() const
- {_RAISE(*this); }
- };
- // CLASS out_of_range
- class _CRTIMP out_of_range : public logic_error {
- public:
- explicit out_of_range(const string& _S)
- : logic_error(_S) {}
- virtual ~out_of_range()
- {}
- protected:
- virtual void _Doraise() const
- {_RAISE(*this); }
- };
- // CLASS runtime_error
- class _CRTIMP runtime_error : public exception {
- public:
- explicit runtime_error(const string& _S)
- : exception(""), _Str(_S) {}
- virtual ~runtime_error()
- {}
- virtual const char *what() const
- {return (_Str.c_str()); }
- protected:
- virtual void _Doraise() const
- {_RAISE(*this); }
- private:
- string _Str;
- };
- // CLASS overflow_error
- class _CRTIMP overflow_error : public runtime_error {
- public:
- explicit overflow_error(const string& _S)
- : runtime_error(_S) {}
- virtual ~overflow_error()
- {}
- protected:
- virtual void _Doraise() const
- {_RAISE(*this); }
- };
- // CLASS underflow_error
- class _CRTIMP underflow_error : public runtime_error {
- public:
- explicit underflow_error(const string& _S)
- : runtime_error(_S) {}
- virtual ~underflow_error()
- {}
- protected:
- virtual void _Doraise() const
- {_RAISE(*this); }
- };
- // CLASS range_error
- class _CRTIMP range_error : public runtime_error {
- public:
- explicit range_error(const string& _S)
- : runtime_error(_S) {}
- virtual ~range_error()
- {}
- protected:
- virtual void _Doraise() const
- {_RAISE(*this); }
- };
- _STD_END
- #ifdef _MSC_VER
- #pragma pack(pop)
- #endif /* _MSC_VER */
- #endif /* _STDEXCEPT_ */
- /*
- * Copyright (c) 1994 by P.J. Plauger. ALL RIGHTS RESERVED.
- * Consult your license regarding permissions and restrictions.
- */
总结:每个类几乎都是由显式带一个参数的构造函数,析构函数, Doraise()函数和一个字符串对象组成.
类之间的关系:
class logic_error; // : public exception
class domain_error; // : public logic_error
class invalid_argument; // : public logic_error
class length_error; // : public logic_error
class out_of_range; // : public logic_error
class runtime_error; // : public exception
class range_error; // : public runtime_error
class overflow_error; // : public runtime_error
class underflow_error; // : public runtime_error
在看看<exception>文件
- /***
- *exception - Defines class exception and related functions
- *
- * Copyright (c) 1994-1997, Microsoft Corporation. All rights reserved.
- * Modified January 1996 by P.J. Plauger
- *
- *Purpose:
- * Defines class exception (and derived class bad_exception)
- * plus new and unexpected handler functions.
- *
- * [Public]
- *
- ****/
- #if _MSC_VER > 1000 /*IFSTRIP=IGN*/
- #pragma once
- #endif
- #ifndef _EXCEPTION_
- #define _EXCEPTION_
- #include <xstddef>
- #include <eh.h>
- #ifdef _MSC_VER
- #pragma pack(push,8)
- #endif /* _MSC_VER */
- #if !defined(_WIN32) && !defined(_MAC)
- #error ERROR: Only Mac or Win32 targets supported!
- #endif
- #ifndef _CRTIMP
- #ifdef _NTSDK
- /* definition compatible with NT SDK */
- #define _CRTIMP
- #else /* ndef _NTSDK */
- /* current definition */
- #ifdef _DLL
- #define _CRTIMP __declspec(dllimport)
- #else /* ndef _DLL */
- #define _CRTIMP
- #endif /* _DLL */
- #endif /* _NTSDK */
- #endif /* _CRTIMP */
- typedef const char *__exString;
- class _CRTIMP exception
- {
- public:
- exception();
- exception(const __exString&);
- exception(const exception&);
- exception& operator= (const exception&);
- virtual ~exception();
- virtual __exString what() const;
- private:
- __exString _m_what;
- int _m_doFree;
- };
- _STD_BEGIN
- using ::exception;
- // CLASS bad_exception
- class _CRTIMP2 bad_exception : public exception {
- public:
- bad_exception(const char *_S = "bad exception") _THROW0()
- : exception(_S) {}
- virtual ~bad_exception() _THROW0()
- {}
- protected:
- virtual void _Doraise() const
- {_RAISE(*this); }
- };
- _CRTIMP2 bool __cdecl uncaught_exception();
- _STD_END
- #ifdef __RTTI_OLDNAMES
- typedef exception xmsg; // A synonym for folks using older standard
- #endif
- #ifdef _MSC_VER
- #pragma pack(pop)
- #endif /* _MSC_VER */
- #endif /* _EXCEPTION_ */
- /*
- * 1994-1995, Microsoft Corporation. All rights reserved.
- * Modified January 1996 by P.J. Plauger
- * Consult your license regarding permissions and restrictions.
- */
继续追踪看<eh.h>文件
- /***
- *eh.h - User include file for exception handling.
- *
- * Copyright (c) 1993-1997, Microsoft Corporation. All rights reserved.
- *
- *Purpose:
- * User include file for exception handling.
- *
- * [Public]
- *
- ****/
- #if _MSC_VER > 1000
- #pragma once
- #endif
- #ifndef _INC_EH
- #define _INC_EH
- #if !defined(_WIN32) && !defined(_MAC)
- #error ERROR: Only Mac or Win32 targets supported!
- #endif
- #ifdef _MSC_VER
- // Currently, all MS C compilers for Win32 platforms default to 8 byte
- // alignment.
- #pragma pack(push,8)
- #endif // _MSC_VER
- #ifndef __cplusplus
- #error "eh.h is only for C++!"
- #endif
- /* Define _CRTIMP */
- #ifndef _CRTIMP
- #ifdef _DLL
- #define _CRTIMP __declspec(dllimport)
- #else /* ndef _DLL */
- #define _CRTIMP
- #endif /* _DLL */
- #endif /* _CRTIMP */
- /* Define _CRTAPI1 (for compatibility with the NT SDK) */
- #ifndef _CRTAPI1
- #if _MSC_VER >= 800 && _M_IX86 >= 300
- #define _CRTAPI1 __cdecl
- #else
- #define _CRTAPI1
- #endif
- #endif
- typedef void (__cdecl *terminate_function)();
- typedef void (__cdecl *unexpected_function)();
- typedef void (__cdecl *terminate_handler)();
- typedef void (__cdecl *unexpected_handler)();
- #ifndef _MAC
- struct _EXCEPTION_POINTERS;
- typedef void (__cdecl *_se_translator_function)(unsigned int, struct _EXCEPTION_POINTERS*);
- #endif
- #if _MSC_VER >= 1200
- _CRTIMP __declspec(noreturn) void __cdecl terminate(void);
- _CRTIMP __declspec(noreturn) void __cdecl unexpected(void);
- #else
- _CRTIMP void __cdecl terminate(void);
- _CRTIMP void __cdecl unexpected(void);
- #endif
- _CRTIMP terminate_function __cdecl set_terminate(terminate_function);
- _CRTIMP unexpected_function __cdecl set_unexpected(unexpected_function);
- #ifndef _MAC
- _CRTIMP _se_translator_function __cdecl _set_se_translator(_se_translator_function);
- #endif
- #ifdef _MSC_VER
- #pragma pack(pop)
- #endif // _MSC_VER
- #endif // _INC_EH
总结:由EH.h和exception文件可得出
typedef const char *__exString;
class exception;
class _bad_exception : public exception ;
bool _ uncaught_exception();
typedef void ( *terminate_function)();
typedef void ( *unexpected_function)();
typedef void ( *terminate_handler)();
typedef void ( *unexpected_handler)();
typedef void ( *_se_translator_function)(unsigned int, struct _EXCEPTION_POINTERS*);
void terminate();
void unexpected();
terminate_handler set_terminate(terminate_handler) throw();
unexpected_handler set_unexpected(unexpected_handler) throw();