seh.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. ///////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/msw/seh.h
  3. // Purpose: declarations for SEH (structured exceptions handling) support
  4. // Author: Vadim Zeitlin
  5. // Created: 2006-04-26
  6. // Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
  7. // Licence: wxWindows licence
  8. ///////////////////////////////////////////////////////////////////////////////
  9. #ifndef _WX_MSW_SEH_H_
  10. #define _WX_MSW_SEH_H_
  11. #if wxUSE_ON_FATAL_EXCEPTION
  12. // the exception handler which should be called from the exception filter
  13. //
  14. // it calsl wxApp::OnFatalException() if possible
  15. extern unsigned long wxGlobalSEHandler(EXCEPTION_POINTERS *pExcPtrs);
  16. // helper macro for wxSEH_HANDLE
  17. #if defined(__BORLANDC__) || (defined(__VISUALC__) && (__VISUALC__ <= 1200))
  18. // some compilers don't understand that this code is unreachable and warn
  19. // about no value being returned from the function without it, so calm them
  20. // down
  21. #define wxSEH_DUMMY_RETURN(rc) return rc;
  22. #else
  23. #define wxSEH_DUMMY_RETURN(rc)
  24. #endif
  25. // macros which allow to avoid many #if wxUSE_ON_FATAL_EXCEPTION in the code
  26. // which uses them
  27. #define wxSEH_TRY __try
  28. #define wxSEH_IGNORE __except ( EXCEPTION_EXECUTE_HANDLER ) { }
  29. #define wxSEH_HANDLE(rc) \
  30. __except ( wxGlobalSEHandler(GetExceptionInformation()) ) \
  31. { \
  32. /* use the same exit code as abort() */ \
  33. ::ExitProcess(3); \
  34. \
  35. wxSEH_DUMMY_RETURN(rc) \
  36. }
  37. #else // wxUSE_ON_FATAL_EXCEPTION
  38. #define wxSEH_TRY
  39. #define wxSEH_IGNORE
  40. #define wxSEH_HANDLE(rc)
  41. #endif // wxUSE_ON_FATAL_EXCEPTION
  42. #if wxUSE_ON_FATAL_EXCEPTION && defined(__VISUALC__) && !defined(__WXWINCE__)
  43. #include <eh.h>
  44. // C++ exception to structured exceptions translator: we need it in order
  45. // to prevent VC++ from "helpfully" translating structured exceptions (such
  46. // as division by 0 or access violation) to C++ pseudo-exceptions
  47. extern void wxSETranslator(unsigned int code, EXCEPTION_POINTERS *ep);
  48. // up to VC 12 this warning ("calling _set_se_translator() requires /EHa")
  49. // is harmless and it's easier to suppress it than use different makefiles
  50. // for VC5 and 6 (which don't support /EHa at all) and VC7+ (which does
  51. // accept it but it seems to change nothing for it anyhow)
  52. #if __VISUALC__ < 1900
  53. #pragma warning(disable: 4535)
  54. #endif
  55. // note that the SE translator must be called wxSETranslator!
  56. #define DisableAutomaticSETranslator() _set_se_translator(wxSETranslator)
  57. #else // !__VISUALC__
  58. // the other compilers do nothing as stupid by default so nothing to do for
  59. // them
  60. #define DisableAutomaticSETranslator()
  61. #endif // __VISUALC__/!__VISUALC__
  62. #endif // _WX_MSW_SEH_H_