Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

110 lines
2.6 KiB

  1. /***
  2. *oldexcpt.cpp - defines C++ standard exception classes
  3. *
  4. * Copyright (c) 1994-2001, Microsoft Corporation. All rights reserved.
  5. *
  6. *Purpose:
  7. * Implementation of C++ standard exception classes, as specified in
  8. * [lib.header.exception] (section 17.3.2 of 5/27/94 WP):
  9. *
  10. * exception (formerly xmsg)
  11. * logic
  12. * domain
  13. * runtime
  14. * range
  15. * alloc
  16. *
  17. *Revision History:
  18. * 04-27-94 BES Module created.
  19. * 10-17-94 BWT Disable code for PPC.
  20. * 02-15-95 JWM Minor cleanups related to Olympus bug 3716
  21. * 07-02-95 JWM Now generally ANSI-compliant; excess baggage removed.
  22. * 01-05-99 GJF Changes for 64-bit size_t.
  23. *
  24. *******************************************************************************/
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include <eh.h>
  28. #include "./oldexcpt.h"
  29. ////////////////////////////////////////////////////////////////////////////////
  30. //
  31. // Implementation of class "exception"
  32. //
  33. //
  34. // Default constructor - initialize to blank
  35. //
  36. exception::exception ()
  37. {
  38. _m_what = NULL;
  39. _m_doFree = 0;
  40. }
  41. //
  42. // Standard constructor: initialize with copy of string
  43. //
  44. exception::exception ( const __exString& what )
  45. {
  46. _m_what = new char[(unsigned int)strlen(what)+1];
  47. if ( _m_what != NULL )
  48. strcpy( (char*)_m_what, what );
  49. _m_doFree = 1;
  50. }
  51. //
  52. // Copy constructor
  53. //
  54. exception::exception ( const exception & that )
  55. {
  56. _m_doFree = that._m_doFree;
  57. if (_m_doFree)
  58. {
  59. _m_what = new char[(unsigned int)strlen(that._m_what) + 1];
  60. if (_m_what != NULL)
  61. strcpy( (char*)_m_what, that._m_what );
  62. }
  63. else
  64. _m_what = that._m_what;
  65. }
  66. //
  67. // Assignment operator: destruct, then copy-construct
  68. //
  69. exception& exception::operator=( const exception& that )
  70. {
  71. if (this != &that)
  72. {
  73. this->exception::~exception();
  74. this->exception::exception(that);
  75. }
  76. return *this;
  77. }
  78. //
  79. // Destructor: free the storage used by the message string if it was
  80. // dynamicly allocated
  81. //
  82. exception::~exception()
  83. {
  84. if (_m_doFree)
  85. delete[] (char*)_m_what;
  86. }
  87. //
  88. // exception::what
  89. // Returns the message string of the exception.
  90. // Default implementation of this method returns the stored string if there
  91. // is one, otherwise returns a standard string.
  92. //
  93. __exString exception::what() const
  94. {
  95. if ( _m_what != NULL )
  96. return _m_what;
  97. else
  98. return "Unknown exception";
  99. }