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.

181 lines
3.8 KiB

  1. /**************************************************************************************************
  2. FILENAME: ErrMacro.h
  3. COPYRIGHT 2001 Microsoft Corporation and Executive Software International, Inc.
  4. DESCRIPTION:
  5. Error handling macros.
  6. **************************************************************************************************/
  7. #include <assert.h>
  8. // set up some aliases
  9. #define require(exp) assert(exp)
  10. #define ensure(exp) assert(exp)
  11. #define invariant(exp) assert(exp)
  12. #define LOG_ERR() LogErrForMacro(TEXT(__FILE__), TEXT(__TIMESTAMP__), __LINE__)
  13. // handle logging to message window and or error log file
  14. void LogErrForMacro(LPTSTR filename, LPTSTR timestamp, UINT lineno);
  15. /****************************** EF DEFINITIONS ***************************************/
  16. //EF's will return debugging information in debug mode, but will not compile in for release builds.
  17. //If an error occurs, handle and return FALSE
  18. #define EF(FunctionCall) \
  19. { \
  20. if (!(FunctionCall)) { \
  21. LOG_ERR(); \
  22. return FALSE; \
  23. } \
  24. }
  25. //If an error occurs, handle and continue on without returning
  26. #define EH(FunctionCall) \
  27. { \
  28. if(!(FunctionCall)) { \
  29. LOG_ERR(); \
  30. } \
  31. }
  32. //If an error occurs, handle and return NULL
  33. #define EN(FunctionCall) \
  34. { \
  35. if(!(FunctionCall)) { \
  36. LOG_ERR(); \
  37. return NULL; \
  38. } \
  39. }
  40. //If an error occurs, handle and return VOID
  41. #define EV(FunctionCall) \
  42. { \
  43. if(!(FunctionCall)) { \
  44. LOG_ERR(); \
  45. return; \
  46. } \
  47. }
  48. //If an error occurs, handle and break (not return)
  49. #define EB(FunctionCall) \
  50. { \
  51. if(!(FunctionCall)) { \
  52. LOG_ERR(); \
  53. break; \
  54. } \
  55. }
  56. //If an error occurs, handle and continue (not return)
  57. #define EC(FunctionCall) \
  58. { \
  59. if(!(FunctionCall)) { \
  60. LOG_ERR(); \
  61. continue; \
  62. } \
  63. }
  64. //If an error occurs, handle and return E_FAIL
  65. #define EE(FunctionCall) \
  66. { \
  67. if(!(FunctionCall)) { \
  68. LOG_ERR(); \
  69. return E_FAIL; \
  70. } \
  71. }
  72. //If an error occurs, handle and return -1
  73. #define EM(FunctionCall) \
  74. { \
  75. if(!(FunctionCall)) { \
  76. LOG_ERR(); \
  77. return -1; \
  78. } \
  79. }
  80. /****************************** EF DEFINITIONS ***************************************/
  81. //EF_ASSERTS's are the same as EF's, except they assert before returning.
  82. //If an error occurs, handle and return FALSE
  83. #define EF_ASSERT(FunctionCall) \
  84. { \
  85. if(!(FunctionCall)) { \
  86. LOG_ERR(); \
  87. assert(FALSE); \
  88. return FALSE; \
  89. } \
  90. }
  91. //If an error occurs, handle and continue on without returning
  92. #define EH_ASSERT(FunctionCall) \
  93. { \
  94. if(!(FunctionCall)) { \
  95. LOG_ERR(); \
  96. assert(FALSE); \
  97. } \
  98. }
  99. //If an error occurs, handle and return NULL
  100. #define EN_ASSERT(FunctionCall) \
  101. { \
  102. if(!(FunctionCall)) { \
  103. LOG_ERR(); \
  104. assert(FALSE); \
  105. return NULL; \
  106. } \
  107. }
  108. //If an error occurs, handle and return VOID
  109. #define EV_ASSERT(FunctionCall) \
  110. { \
  111. if(!(FunctionCall)) { \
  112. LOG_ERR(); \
  113. assert(FALSE); \
  114. return; \
  115. } \
  116. }
  117. //If an error occurs, handle and break (not return)
  118. #define EB_ASSERT(FunctionCall) \
  119. { \
  120. if(!(FunctionCall)) { \
  121. LOG_ERR(); \
  122. assert(FALSE); \
  123. break; \
  124. } \
  125. }
  126. //If an error occurs, handle and continue (not return)
  127. #define EC_ASSERT(FunctionCall) \
  128. { \
  129. if(!(FunctionCall)) { \
  130. LOG_ERR(); \
  131. assert(FALSE); \
  132. continue; \
  133. } \
  134. }
  135. //If an error occurs, handle and return E_FAIL
  136. #define EE_ASSERT(FunctionCall) \
  137. { \
  138. if(!(FunctionCall)) { \
  139. LOG_ERR(); \
  140. assert(FALSE); \
  141. return E_FAIL; \
  142. } \
  143. }
  144. //If an error occurs, handle and return -1
  145. #define EM_ASSERT(FunctionCall) \
  146. { \
  147. if(!(FunctionCall)) { \
  148. LOG_ERR(); \
  149. assert(FALSE); \
  150. return -1; \
  151. } \
  152. }