From: Phillip S. <ps...@cf...> - 2002-01-08 23:07:25
|
I'm a little confused here. C++ exceptions are caught with a try/catch block, win32 SEH exceptions are caught with a __try/__except block. gcc does not support SEH exceptions. I'm not sure why your code there has a try { __try1 in it. try is a C++ try, what is __try1 and __except1? If you want to catch an access violation, you need to use a SEH exception handler; C++ catch statements will not catch seg faults ( unless the compiler is very broken and non compliant, like VC 5 was ). At 09:57 PM 1/3/2002 -0800, you wrote: >I'm attaching a GCC-compiled C++ DLL to a Windows application (XEmacs >21.4.6). In my DLL, I need to catch segfaults, so I've set up this >structured exception handler: > >inline >EXCEPTION_DISPOSITION >_catch1(_EXCEPTION_RECORD *exception_record, > void *err, > _CONTEXT *context, > void *par) >{ > throw exception_record; >} > >#define CHECK_FOR_HARMONIA_ERROR_BEGIN() \ > try { \ > __try1(_catch1) > >#define CHECK_FOR_HARMONIA_ERROR_END() \ > __except1 \ > } catch(_EXCEPTION_RECORD *seh) { \ > if (error_handler != NULL) \ > error_handler(seh_to_pooled_string(seh)); \ > } catch(PooledString pserror) { \ > if (error_handler != NULL) \ > error_handler(pserror); \ > } > >I wrap calls with CHECK_FOR_HARMONIA_ERROR_BEGIN() and END, and should >call an error handler I defined that prints out a message to XEmacs' >console. > >If I compile XEmacs (a C application) with GCC (mingw), instead of >catching any errors, my application disappears whenever a segfault >occurs. I used VisStudio to debug XEmacs and catch the exception, and it >said that there was a segfault while running _local_unwind2. From what I >know of that function, that's what happens when MS is trying to run your >exception handler. From the PC, it appears it's my exception that's >running, and since there's only one line, it's the C++ throw call that's >failing to execute. > >However, and here's the funny thing, if I compile XEmacs with MSVC, >first of all, my segfault (which above occurred in my DLL and is handled >there, not in XEmacs) doesn't occur, and I can't catch exceptions at >all. When a real segfault does occur (M-x make-harmonia-segfault <grin>) >I get an abnormal termination error dialog box from MS Windows 2000, >which means my exception handler didn't run at all. > >What's going on here? On one hand, i have a spurious seg fault that >causes my exception handler to itself segfault, and then just by >changing the host executable for my DLL, the segfault goes away, but any >ability to catch C exceptions does too. > >Does anyone have any insight into this? Are there any libraries that gcc >links into a binary executable that can affect the DLLs that are loaded? >How do C++ DLLs deal with being loaded into C executables? Do they come >with their own exception library that g++ links in? > >Thanks > >andrew |