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.

111 lines
4.6 KiB

  1. // ExceptionContext.h -- Exception Context class definition
  2. // (c) Copyright Schlumberger Technology Corp., unpublished work,
  3. // created 2001. This computer program includes Confidential,
  4. // Proprietary Information and is a Trade Secret of Schlumberger
  5. // Technology Corp. All use, disclosure, and/or reproduction is
  6. // prohibited unless authorized in writing. All Rights Reserved.
  7. #if !defined(SLBCSP_EXCEPTIONCONTEXT_H)
  8. #define SLBCSP_EXCEPTIONCONTEXT_H
  9. #include <memory> // for auto_ptr
  10. #include <scuOsExc.h>
  11. /////////////////////////// HELPERS /////////////////////////////////
  12. // Macros to trap exceptions and set the exception context
  13. // appropriately with an optionally throw.
  14. #define EXCCTX_TRY \
  15. { \
  16. try
  17. #define EXCCTX_CATCH(pExcCtx, fDoThrow) \
  18. catch (scu::Exception const &rExc) \
  19. { \
  20. if (!pExcCtx->Exception()) \
  21. pExcCtx->Exception(auto_ptr<scu::Exception const>(rExc.Clone())); \
  22. } \
  23. \
  24. catch (std::bad_alloc const &) \
  25. { \
  26. if (!pExcCtx->Exception()) \
  27. pExcCtx->Exception(auto_ptr<scu::Exception const>(scu::OsException(NTE_NO_MEMORY).Clone())); \
  28. } \
  29. \
  30. catch (...) \
  31. { \
  32. if (!pExcCtx->Exception()) \
  33. pExcCtx->Exception(auto_ptr<scu::Exception const>(scu::OsException(NTE_FAIL).Clone())); \
  34. } \
  35. \
  36. if (fDoThrow) \
  37. pExcCtx->PropagateException(); \
  38. }
  39. // Abstract base class mixin for derived classes that want to maintain
  40. // an exception context. Typically this is used in conjuction with
  41. // calling conventional libraries that require a callback routine and
  42. // that callback routine want to raise exceptions which shouldn't be
  43. // thrown across the library.
  44. class ExceptionContext
  45. {
  46. public:
  47. // Types
  48. // C'tors/D'tors
  49. explicit
  50. ExceptionContext();
  51. virtual
  52. ~ExceptionContext();
  53. // Operators
  54. // Operations
  55. void
  56. Exception(std::auto_ptr<scu::Exception const> &rapexc);
  57. void
  58. ClearException();
  59. void
  60. PropagateException();
  61. void
  62. PropagateException(std::auto_ptr<scu::Exception const> &rapExc);
  63. // Access
  64. scu::Exception const *
  65. Exception() const;
  66. // Predicates
  67. protected:
  68. // Types
  69. // C'tors/D'tors
  70. // Operators
  71. // Operations
  72. // Access
  73. // Predicates
  74. // Variables
  75. private:
  76. // Types
  77. // C'tors/D'tors
  78. ExceptionContext(ExceptionContext const &rhs); // not defined, copying not allowed
  79. // Operators
  80. ExceptionContext &
  81. operator=(ExceptionContext const &rhs); // not defined, assignment not allowed
  82. // Operations
  83. // Access
  84. // Predicates
  85. // Variables
  86. std::auto_ptr<scu::Exception const> m_apexception;
  87. };
  88. #endif // SLBCSP_EXCEPTIONCONTEXT_H