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.

56 lines
1.6 KiB

  1. //==========================================================================;
  2. //
  3. // throw.h : exception handling code
  4. // Copyright (c) Microsoft Corporation 1998.
  5. //
  6. /////////////////////////////////////////////////////////////////////////////
  7. #pragma once
  8. #ifndef THROW_H
  9. #define THROW_H
  10. class ComException {
  11. public:
  12. ComException(HRESULT hr) : m_hr(hr) {}
  13. ComException(ComException &ce) : m_hr(ce.m_hr) {}
  14. ComException& operator=(ComException &rhs) {
  15. if (this != &rhs) {
  16. m_hr = rhs.m_hr;
  17. }
  18. return *this;
  19. }
  20. ComException& operator=(HRESULT rhs) {
  21. m_hr = rhs;
  22. return *this;
  23. }
  24. operator HRESULT() {
  25. return m_hr;
  26. }
  27. private:
  28. HRESULT m_hr;
  29. };
  30. #define THROWCOM(x) throw ComException(x)
  31. #define CATCHCOM_CLEANUP(x) catch (ComException& e) { \
  32. { x; } \
  33. return e; \
  34. }
  35. #define CATCHCOM() CATCHCOM_CLEANUP(;)
  36. #define CATCHALL_CLEANUP(x) CATCHCOM_CLEANUP(x) \
  37. catch (std::bad_alloc& e) { \
  38. { x; } \
  39. return E_OUTOFMEMORY; \
  40. } catch (std::exception& e) { \
  41. { x; } \
  42. return E_UNEXPECTED; \
  43. }
  44. #define CATCHALL() CATCHALL_CLEANUP(;)
  45. #endif
  46. // end of file throw.h