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.

78 lines
2.2 KiB

  1. /*-----------------------------------------------------------------------------
  2. Microsoft Denali
  3. Microsoft Confidential
  4. Copyright 1996 Microsoft Corporation. All Rights Reserved.
  5. Component: Exception Handling
  6. File: Except.h
  7. Owner: DGottner
  8. Exception handling macros implemented via Win32 structured exceptions.
  9. Usage:
  10. TRY
  11. <try block>
  12. CATCH (<exception variable>)
  13. <exception handler>
  14. END_TRY
  15. To throw an exception use "THROW (<integer expression>)"
  16. To set up a termination handler use:
  17. TRY
  18. <try block>
  19. FINALLY
  20. <termination handler>
  21. END_TRY
  22. Rationale:
  23. This macro package offers a strict subset of Win32 structured exception
  24. handling. There is no support for exception filters (you have to rethrow
  25. exceptions), and no support for the resumption model of exception handling
  26. (though Win32 supports the resumption model)
  27. The purpose for these restrictions is to make it very easy to rewrite the
  28. exception handling macros for use with other exception throwing mechanisms.
  29. It would be easy to use this same interface with C++ exceptions or
  30. setjmp/longjmp.
  31. The braces with TRY, CATCH, and FINALLY are optional. Since this code is
  32. structured using self-bracketing constructs, the braces seem redundant.
  33. There is no need to declare the datatype of the <exception variable>
  34. because it is always an integer.
  35. -----------------------------------------------------------------------------*/
  36. #ifndef _EXCEPT_H
  37. #define _EXCEPT_H
  38. // Pragmas --------------------------------------------------------------------
  39. //
  40. // Turn off the "signed/unsigned conversion" warning off because it we get this
  41. // all the time that we throw an HRESULT. (which is a harmless thing) The
  42. // warning is usually benign anyway.
  43. #pragma warning(disable: 4245)
  44. // Macros ---------------------------------------------------------------------
  45. #define TRY __try {
  46. #define CATCH(nException) } __except(1) { DWORD nException = GetExceptionCode();
  47. #define FINALLY } __finally {
  48. #define END_TRY }
  49. #define THROW(nException) RaiseException(nException, 0, 0, NULL)
  50. #endif // _EXCEPT_H