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.

125 lines
2.9 KiB

  1. /*++
  2. ****COPYRIGHT NOTICE*****
  3. Module Name:
  4. trycatch.h
  5. Abstract:
  6. This module provides macros to support a lexical-scope exception-handling
  7. mechanism. A brief comparison between this mechanism and the C++ exception
  8. mechanism is as follows:
  9. macro exception mechamism:
  10. extremely low run-time overhead
  11. catches exceptions only in lexical scope
  12. no value passed to exception handler
  13. explicitly thrown exceptions only
  14. exception regions can be nested and named
  15. usable by older compilers
  16. C++ exception mechanism:
  17. handles all types of exceptions including C exceptions implicity
  18. thrown.
  19. catches exceptions thrown in dynamic scope
  20. involves some setup and teardown run-time overhead
  21. requires an up-to-date C++ compiler version
  22. These macros are written and used in such a fashion that they can be
  23. transformed back into the C++ exception mechanism if needed.
  24. Author:
  25. Paul Drews (drewsxpa@ashland.intel.com) 31-October-1995
  26. Notes:
  27. $Revision: 1.2 $
  28. $Modtime: 12 Jan 1996 15:09:02 $
  29. Revision History:
  30. most-recent-revision-date email-name
  31. description
  32. 31-October-1995 drewsxpa@ashland.intel.com
  33. created
  34. --*/
  35. #ifndef _TRYCATCH_
  36. #define _TRYCATCH_
  37. // The TRY_START macro starts a guarded region
  38. #define TRY_START(block_label) \
  39. /* nothing to do */
  40. // The TRY_THROW macro is used inside a guarded region to exit the guarded
  41. // region immediately and enter the exception-recovery region.
  42. #define TRY_THROW(block_label) \
  43. goto catch_##block_label
  44. // The TRY_CATCH macro marks the end of the guarded region and starts the
  45. // beginning of the exception-recovery region. If the TRY_CATCH macro is
  46. // encountered in normal execution, the exception-recovery region is skipped.
  47. #define TRY_CATCH(block_label) \
  48. goto end_##block_label; \
  49. catch_##block_label:
  50. // The TRY_END macro marks the end of the exception-recovery region. Execution
  51. // resumes here after completing execution of either the guarded region or the
  52. // exception-recovery region.
  53. #define TRY_END(block_label) \
  54. end_##block_label:
  55. // A typical usage example of these macros is as follows:
  56. //
  57. // char * buf1 = NULL;
  58. // char * buf2 = NULL;
  59. // BOOL return_value;
  60. //
  61. // TRY_START(mem_guard) {
  62. // buf1 = (char *) malloc(1000);
  63. // if (buf1 == NULL) {
  64. // TRY_THROW(mem_guard);
  65. // }
  66. // buf2 = (char *) malloc(1000);
  67. // if (buf2 == NULL) {
  68. // TRY_THROW(mem_guard);
  69. // }
  70. // return_value = TRUE;
  71. // } TRY_CATCH(mem_guard) {
  72. // if (buf1 != NULL) {
  73. // free(buf1);
  74. // buf1 = NULL;
  75. // }
  76. // return_value = FALSE;
  77. // } TRY_END(mem_guard);
  78. //
  79. // return return_value;
  80. #endif // _TRYCATCH_