我看VC6.0 异常头文件

vc6.0自带的<stdexcept>文件.
 
  1. // stdexcept standard header
  2. #if     _MSC_VER > 1000
  3. #pragma once
  4. #endif
  5. #ifndef _STDEXCEPT_
  6. #define _STDEXCEPT_
  7. #include <exception>
  8. #include <xstring>
  9. #ifdef  _MSC_VER
  10. #pragma pack(push,8)
  11. #endif  /* _MSC_VER */
  12. _STD_BEGIN
  13.         // CLASS logic_error
  14. class _CRTIMP logic_error : public exception {
  15. public:
  16.     explicit logic_error(const string& _S)
  17.         : exception(""), _Str(_S) {}
  18.     virtual ~logic_error()
  19.         {}
  20.     virtual const char *what() const
  21.         {return (_Str.c_str()); }
  22. protected:
  23.     virtual void _Doraise() const
  24.         {_RAISE(*this); }
  25. private:
  26.     string _Str;
  27.     };
  28.         // CLASS domain_error
  29. class _CRTIMP domain_error : public logic_error {
  30. public:
  31.     explicit domain_error(const string& _S)
  32.         : logic_error(_S) {}
  33.     virtual ~domain_error()
  34.         {}
  35. protected:
  36.     virtual void _Doraise() const
  37.         {_RAISE(*this); }
  38.     };
  39.         // CLASS invalid_argument
  40. class invalid_argument : public logic_error {
  41. public:
  42.     explicit invalid_argument(const string& _S)
  43.         : logic_error(_S) {}
  44.     virtual ~invalid_argument()
  45.         {}
  46. protected:
  47.     virtual void _Doraise() const
  48.         {_RAISE(*this); }
  49.     };
  50.         // CLASS length_error
  51. class _CRTIMP length_error : public logic_error {
  52. public:
  53.     explicit length_error(const string& _S)
  54.         : logic_error(_S) {}
  55.     virtual ~length_error()
  56.         {}
  57. protected:
  58.     virtual void _Doraise() const
  59.         {_RAISE(*this); }
  60.     };
  61.         // CLASS out_of_range
  62. class _CRTIMP out_of_range : public logic_error {
  63. public:
  64.     explicit out_of_range(const string& _S)
  65.         : logic_error(_S) {}
  66.     virtual ~out_of_range()
  67.         {}
  68. protected:
  69.     virtual void _Doraise() const
  70.         {_RAISE(*this); }
  71.     };
  72.         // CLASS runtime_error
  73. class _CRTIMP runtime_error : public exception {
  74. public:
  75.     explicit runtime_error(const string& _S)
  76.         : exception(""), _Str(_S) {}
  77.     virtual ~runtime_error()
  78.         {}
  79.     virtual const char *what() const
  80.         {return (_Str.c_str()); }
  81. protected:
  82.     virtual void _Doraise() const
  83.         {_RAISE(*this); }
  84. private:
  85.     string _Str;
  86.     };
  87.         // CLASS overflow_error
  88. class _CRTIMP overflow_error : public runtime_error {
  89. public:
  90.     explicit overflow_error(const string& _S)
  91.         : runtime_error(_S) {}
  92.     virtual ~overflow_error()
  93.         {}
  94. protected:
  95.     virtual void _Doraise() const
  96.         {_RAISE(*this); }
  97.     };
  98.         // CLASS underflow_error
  99. class _CRTIMP underflow_error : public runtime_error {
  100. public:
  101.     explicit underflow_error(const string& _S)
  102.         : runtime_error(_S) {}
  103.     virtual ~underflow_error()
  104.         {}
  105. protected:
  106.     virtual void _Doraise() const
  107.         {_RAISE(*this); }
  108.     };
  109.         // CLASS range_error
  110. class _CRTIMP range_error : public runtime_error {
  111. public:
  112.     explicit range_error(const string& _S)
  113.         : runtime_error(_S) {}
  114.     virtual ~range_error()
  115.         {}
  116. protected:
  117.     virtual void _Doraise() const
  118.         {_RAISE(*this); }
  119.     };
  120. _STD_END
  121. #ifdef  _MSC_VER
  122. #pragma pack(pop)
  123. #endif  /* _MSC_VER */
  124. #endif /* _STDEXCEPT_ */
  125. /*
  126.  * Copyright (c) 1994 by P.J. Plauger.  ALL RIGHTS RESERVED. 
  127.  * Consult your license regarding permissions and restrictions.
  128.  */

总结:每个类几乎都是由显式带一个参数的构造函数,析构函数, 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>文件

  1. /***
  2. *exception - Defines class exception and related functions
  3. *
  4. *   Copyright (c) 1994-1997, Microsoft Corporation. All rights reserved.
  5. *   Modified January 1996 by P.J. Plauger
  6. *
  7. *Purpose:
  8. *       Defines class exception (and derived class bad_exception)
  9. *       plus new and unexpected handler functions.
  10. *
  11. *       [Public]
  12. *
  13. ****/
  14. #if     _MSC_VER > 1000 /*IFSTRIP=IGN*/
  15. #pragma once
  16. #endif
  17. #ifndef _EXCEPTION_
  18. #define _EXCEPTION_
  19. #include <xstddef>
  20. #include <eh.h>
  21. #ifdef  _MSC_VER
  22. #pragma pack(push,8)
  23. #endif  /* _MSC_VER */
  24.  #if !defined(_WIN32) && !defined(_MAC)
  25.   #error ERROR: Only Mac or Win32 targets supported!
  26.  #endif
  27. #ifndef _CRTIMP
  28. #ifdef  _NTSDK
  29. /* definition compatible with NT SDK */
  30. #define _CRTIMP
  31. #else   /* ndef _NTSDK */
  32. /* current definition */
  33. #ifdef  _DLL
  34. #define _CRTIMP __declspec(dllimport)
  35. #else   /* ndef _DLL */
  36. #define _CRTIMP
  37. #endif  /* _DLL */
  38. #endif  /* _NTSDK */
  39. #endif  /* _CRTIMP */
  40. typedef const char *__exString;
  41. class _CRTIMP exception
  42. {
  43. public:
  44.     exception();
  45.     exception(const __exString&);
  46.     exception(const exception&);
  47.     exception& operator= (const exception&);
  48.     virtual ~exception();
  49.     virtual __exString what() const;
  50. private:
  51.     __exString _m_what;
  52.     int _m_doFree;
  53. };
  54. _STD_BEGIN
  55. using ::exception;
  56.         // CLASS bad_exception
  57. class _CRTIMP2 bad_exception : public exception {
  58. public:
  59.     bad_exception(const char *_S = "bad exception") _THROW0()
  60.         : exception(_S) {}
  61.     virtual ~bad_exception() _THROW0()
  62.         {}
  63. protected:
  64.     virtual void _Doraise() const
  65.         {_RAISE(*this); }
  66.     };
  67. _CRTIMP2 bool __cdecl uncaught_exception();
  68. _STD_END
  69. #ifdef __RTTI_OLDNAMES
  70. typedef exception xmsg;        // A synonym for folks using older standard
  71. #endif
  72. #ifdef  _MSC_VER
  73. #pragma pack(pop)
  74. #endif  /* _MSC_VER */
  75. #endif /* _EXCEPTION_ */
  76. /*
  77.  * 1994-1995, Microsoft Corporation. All rights reserved.
  78.  * Modified January 1996 by P.J. Plauger
  79.  * Consult your license regarding permissions and restrictions.
  80.  */

继续追踪看<eh.h>文件

  1. /***
  2. *eh.h - User include file for exception handling.
  3. *
  4. *       Copyright (c) 1993-1997, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. *       User include file for exception handling.
  8. *
  9. *       [Public]
  10. *
  11. ****/
  12. #if     _MSC_VER > 1000
  13. #pragma once
  14. #endif
  15. #ifndef _INC_EH
  16. #define _INC_EH
  17. #if     !defined(_WIN32) && !defined(_MAC)
  18. #error ERROR: Only Mac or Win32 targets supported!
  19. #endif
  20. #ifdef  _MSC_VER
  21. // Currently, all MS C compilers for Win32 platforms default to 8 byte
  22. // alignment.
  23. #pragma pack(push,8)
  24. #endif  // _MSC_VER
  25. #ifndef __cplusplus
  26. #error "eh.h is only for C++!"
  27. #endif
  28. /* Define _CRTIMP */
  29. #ifndef _CRTIMP
  30. #ifdef  _DLL
  31. #define _CRTIMP __declspec(dllimport)
  32. #else   /* ndef _DLL */
  33. #define _CRTIMP
  34. #endif  /* _DLL */
  35. #endif  /* _CRTIMP */
  36. /* Define _CRTAPI1 (for compatibility with the NT SDK) */
  37. #ifndef _CRTAPI1
  38. #if _MSC_VER >= 800 && _M_IX86 >= 300
  39. #define _CRTAPI1 __cdecl
  40. #else
  41. #define _CRTAPI1
  42. #endif
  43. #endif
  44. typedef void (__cdecl *terminate_function)();
  45. typedef void (__cdecl *unexpected_function)();
  46. typedef void (__cdecl *terminate_handler)();
  47. typedef void (__cdecl *unexpected_handler)();
  48. #ifndef _MAC
  49. struct _EXCEPTION_POINTERS;
  50. typedef void (__cdecl *_se_translator_function)(unsigned intstruct _EXCEPTION_POINTERS*);
  51. #endif
  52. #if     _MSC_VER >= 1200
  53. _CRTIMP __declspec(noreturnvoid __cdecl terminate(void);
  54. _CRTIMP __declspec(noreturnvoid __cdecl unexpected(void);
  55. #else
  56. _CRTIMP void __cdecl terminate(void);
  57. _CRTIMP void __cdecl unexpected(void);
  58. #endif
  59. _CRTIMP terminate_function __cdecl set_terminate(terminate_function);
  60. _CRTIMP unexpected_function __cdecl set_unexpected(unexpected_function);
  61. #ifndef _MAC
  62. _CRTIMP _se_translator_function __cdecl _set_se_translator(_se_translator_function);
  63. #endif
  64. #ifdef  _MSC_VER
  65. #pragma pack(pop)
  66. #endif  // _MSC_VER
  67. #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();

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值