6 #if defined(__MINGW32__)
7 /* Stuff needed to install and use SEH exception handlers */
11 #elif defined(_MSC_VER)
17 /* Exception handling.
19 * On Win32, the default action for things like division by zero and
20 * segfaults is to pop up an annoying little dialog box.
22 * This is a pain when we are SSHed into a Windows machine, or when we
23 * want to debug a problem with gdb.
25 * seh_excn provides two macros, BEGIN_CATCH and END_CATCH, which
26 * will catch such exceptions in the code they bracket and die by
27 * printing a message and calling exit(1).
29 #define ON_DIV_ZERO fprintf(stdout,"divide by zero\n"); fflush(stdout);exit(1)
30 #define ON_STACK_OVERFLOW fprintf(stdout,"C stack overflow in generated code\n"); fflush(stdout); exit(1)
31 #define ON_SIGSEGV fprintf(stdout,"Segmentation fault/access violation in generated code\n"); fflush(stdout); exit(1)
33 #if defined(__MINGW32__)
34 extern jmp_buf seh_unwind_to;
35 extern unsigned long seh_excn_code;
37 * install an exception handler 'exHandler' which longjmp()s (via 'jumpBuf')
38 * to the code 'onExnCaught' when successfully catching an exception.
40 * Macro based on Andrew Begel's SEH support code posted to the mingw-users
43 #define TRY_BEGIN(jumpBuf, exHandler, onExcnCaught) \
46 if ((signal = setjmp(jumpBuf)) != 0) { \
53 #define TRY_END() __except1
57 catchDivZero(struct _EXCEPTION_RECORD*,
63 if (seh_excn_code == 1) { \
65 } else if ( seh_excn_code == 2 ) { \
71 #define BEGIN_CATCH TRY_BEGIN(seh_unwind_to, catchDivZero, ON_EXCN)
72 #define END_CATCH TRY_END()
73 #elif defined(_MSC_VER)
74 #define BEGIN_CATCH __try {
75 #define END_CATCH } __except ( ( ((GetExceptionCode() == EXCEPTION_FLT_DIVIDE_BY_ZERO) || (GetExceptionCode() == EXCEPTION_INT_DIVIDE_BY_ZERO) || (GetExceptionCode() == EXCEPTION_STACK_OVERFLOW) || (GetExceptionCode() == EXCEPTION_ACCESS_VIOLATION)) ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH ) ) { \
76 switch ( (GetExceptionCode()) ) { \
77 case EXCEPTION_FLT_DIVIDE_BY_ZERO: \
78 case EXCEPTION_INT_DIVIDE_BY_ZERO:
80 case EXCEPTION_STACK_OVERFLOW: \
81 ON_STACK_OVERFLOW; break; \
82 case EXCEPTION_ACCESS_VIOLATION: \
87 #error Don't know what sort of Windows system this is
90 #endif /* __SEH_EXCN_H__ */