Posted to tcl by davygrvy at Fri May 15 19:40:07 GMT 2020view raw

  1. LPTSTR GetExceptionString( DWORD dwCode )
  2. {
  3. # define EXCEPTION(x) case EXCEPTION_##x: return #x;
  4.  
  5. switch (dwCode)
  6. {
  7. EXCEPTION(ACCESS_VIOLATION)
  8. EXCEPTION(DATATYPE_MISALIGNMENT)
  9. EXCEPTION(BREAKPOINT)
  10. EXCEPTION(SINGLE_STEP)
  11. EXCEPTION(ARRAY_BOUNDS_EXCEEDED)
  12. EXCEPTION(FLT_DENORMAL_OPERAND)
  13. EXCEPTION(FLT_DIVIDE_BY_ZERO)
  14. EXCEPTION(FLT_INEXACT_RESULT)
  15. EXCEPTION(FLT_INVALID_OPERATION)
  16. EXCEPTION(FLT_OVERFLOW)
  17. EXCEPTION(FLT_STACK_CHECK)
  18. EXCEPTION(FLT_UNDERFLOW)
  19. EXCEPTION(INT_DIVIDE_BY_ZERO)
  20. EXCEPTION(INT_OVERFLOW)
  21. EXCEPTION(PRIV_INSTRUCTION)
  22. EXCEPTION(IN_PAGE_ERROR)
  23. EXCEPTION(ILLEGAL_INSTRUCTION)
  24. EXCEPTION(NONCONTINUABLE_EXCEPTION)
  25. EXCEPTION(STACK_OVERFLOW)
  26. EXCEPTION(INVALID_DISPOSITION)
  27. EXCEPTION(GUARD_PAGE)
  28. EXCEPTION(INVALID_HANDLE)
  29. }
  30.  
  31. // If not one of the "known" exceptions, try to get the string
  32. // from NTDLL.DLL's message table.
  33.  
  34. static CHAR szBuffer[512] = { 0 };
  35.  
  36. FormatMessage(FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_HMODULE,
  37. GetModuleHandle("NTDLL.DLL"), dwCode, 0, szBuffer,
  38. sizeof(szBuffer), 0);
  39.  
  40. return szBuffer;
  41. }
  42.