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.

97 lines
2.1 KiB

  1. // This is a part of the Active Template Library.
  2. // Copyright (C) 1996-2001 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Active Template Library Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Active Template Library product.
  10. #ifndef __ATLEXCEPT_H__
  11. #define __ATLEXCEPT_H__
  12. #pragma once
  13. #include <atldef.h>
  14. namespace ATL
  15. {
  16. class CAtlException
  17. {
  18. public:
  19. CAtlException() throw() :
  20. m_hr( E_FAIL )
  21. {
  22. }
  23. CAtlException( HRESULT hr ) throw() :
  24. m_hr( hr )
  25. {
  26. }
  27. operator HRESULT() const throw()
  28. {
  29. return( m_hr );
  30. }
  31. public:
  32. HRESULT m_hr;
  33. };
  34. #ifndef _ATL_NO_EXCEPTIONS
  35. // Throw a CAtlException with the given HRESULT
  36. #if defined( AtlThrow ) || defined( _ATL_CUSTOM_THROW ) // You can define your own AtlThrow to throw a custom exception.
  37. #ifdef _AFX
  38. #error MFC projects must use default implementation of AtlThrow()
  39. #endif
  40. #else
  41. ATL_NOINLINE __declspec(noreturn) inline void AtlThrow( HRESULT hr )
  42. {
  43. #ifdef _AFX
  44. if( hr == E_OUTOFMEMORY )
  45. {
  46. AfxThrowMemoryException();
  47. }
  48. else
  49. {
  50. AfxThrowOleException( hr );
  51. }
  52. #else
  53. throw CAtlException( hr );
  54. #endif
  55. };
  56. #endif
  57. // Throw a CAtlException corresponding to the result of ::GetLastError
  58. ATL_NOINLINE __declspec(noreturn) inline void AtlThrowLastWin32()
  59. {
  60. DWORD dwError = ::GetLastError();
  61. AtlThrow( HRESULT_FROM_WIN32( dwError ) );
  62. }
  63. #else // no exception handling
  64. // Throw a CAtlException with the given HRESULT
  65. #if !defined( AtlThrow ) && !defined( _ATL_CUSTOM_THROW ) // You can define your own AtlThrow
  66. ATL_NOINLINE inline void AtlThrow( HRESULT hr )
  67. {
  68. (void)hr;
  69. ATLASSERT( false );
  70. }
  71. #endif
  72. // Throw a CAtlException corresponding to the result of ::GetLastError
  73. ATL_NOINLINE inline void AtlThrowLastWin32()
  74. {
  75. DWORD dwError = ::GetLastError();
  76. AtlThrow( HRESULT_FROM_WIN32( dwError ) );
  77. }
  78. #endif // no exception handling
  79. }; // namespace ATL
  80. #endif // __ATLEXCEPT_H__