Source code of Windows XP (NT5)
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.

100 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. #include <atltrace.h>
  15. namespace ATL
  16. {
  17. class CAtlException
  18. {
  19. public:
  20. CAtlException() throw() :
  21. m_hr( E_FAIL )
  22. {
  23. }
  24. CAtlException( HRESULT hr ) throw() :
  25. m_hr( hr )
  26. {
  27. }
  28. operator HRESULT() const throw()
  29. {
  30. return( m_hr );
  31. }
  32. public:
  33. HRESULT m_hr;
  34. };
  35. #ifndef _ATL_NO_EXCEPTIONS
  36. // Throw a CAtlException with the given HRESULT
  37. #if defined( AtlThrow ) || defined( _ATL_CUSTOM_THROW ) // You can define your own AtlThrow to throw a custom exception.
  38. #ifdef _AFX
  39. #error MFC projects must use default implementation of AtlThrow()
  40. #endif
  41. #else
  42. ATL_NOINLINE __declspec(noreturn) inline void AtlThrow( HRESULT hr )
  43. {
  44. ATLTRACE(atlTraceException, 0, _T("AtlThrow: hr = 0x%x\n"), hr );
  45. #ifdef _AFX
  46. if( hr == E_OUTOFMEMORY )
  47. {
  48. AfxThrowMemoryException();
  49. }
  50. else
  51. {
  52. AfxThrowOleException( hr );
  53. }
  54. #else
  55. throw CAtlException( hr );
  56. #endif
  57. };
  58. #endif
  59. // Throw a CAtlException corresponding to the result of ::GetLastError
  60. ATL_NOINLINE __declspec(noreturn) inline void AtlThrowLastWin32()
  61. {
  62. DWORD dwError = ::GetLastError();
  63. AtlThrow( HRESULT_FROM_WIN32( dwError ) );
  64. }
  65. #else // no exception handling
  66. // Throw a CAtlException with the given HRESULT
  67. #if !defined( AtlThrow ) && !defined( _ATL_CUSTOM_THROW ) // You can define your own AtlThrow
  68. ATL_NOINLINE inline void AtlThrow( HRESULT hr )
  69. {
  70. (void)hr;
  71. ATLTRACE(atlTraceException, 0, _T("AtlThrow: hr = 0x%x\n"), hr );
  72. ATLASSERT( false );
  73. }
  74. #endif
  75. // Throw a CAtlException corresponding to the result of ::GetLastError
  76. ATL_NOINLINE inline void AtlThrowLastWin32()
  77. {
  78. DWORD dwError = ::GetLastError();
  79. AtlThrow( HRESULT_FROM_WIN32( dwError ) );
  80. }
  81. #endif // no exception handling
  82. }; // namespace ATL
  83. #endif // __ATLEXCEPT_H__