On Sun, 2007-07-01 at 09:41 -0400, Kevin O'Connor wrote: > On Fri, Jun 22, 2007 at 09:37:21PM +0200, Danny Backx wrote: > > The null.C example however - when used with my exception handling code - > > shows a dialog from my new exception handler, but never makes its way to > > the C++ exception handler. > > Have you figured out a way to raise a c++ exception from the wince > handler?
Actually I was just getting there minutes ago. > > Running the null.C program on Linux creates a coredump too, no exception > > handler is called. > > Invalid memory accesses don't cause exceptions under Linux. > > Also, it appears gcc may optimize out c++ exception handlers if it > doesn't think the code can create an exception. It thinks it is > running under a linux like environment and the optimizer wont even try > to handle memory raised exceptions. > > > I assumed that the goal is to have the system level exception (from use > > of a null pointer) be caught by the C++ exception handler. Am I wrong ? > > That is certainly what I'd like to see. :-) Ok, attached is the source of my current test program. Comments most welcome. You'll understand that this is just a proof of concept. I've put the executable file on http://danny.backx.info/download/throw.exe.gz so the E-mail isn't too big. You cannot compile this yet, it relies on unpublished stuff. Let me know what you think. Danny -- Danny Backx ; danny.backx - at - scarlet.be ; http://danny.backx.info
#include <iostream>
using namespace std;
extern "C" {
// typedef void (*handler)(void);
typedef void (*handler) (struct _EXCEPTION_RECORD *ExceptionRecord,
void *EstablisherFrame,
struct _CONTEXT *ContextRecord,
struct _DISPATCHER_CONTEXT *DispatcherContext);
void CegccSetExceptionHandler(handler new_handler);
};
#ifdef UNDER_CE
#include <windows.h>
#define Message(title, msg) MessageBoxW(0, L##title, L##msg, 0)
#else
#define Message(title, msg) cout << title << " : " << msg << endl
#endif
class WindowsException {
struct _EXCEPTION_RECORD *ExceptionRecord;
void *EstablisherFrame;
struct _CONTEXT *ContextRecord;
struct _DISPATCHER_CONTEXT *DispatcherContext;
public:
WindowsException(struct _EXCEPTION_RECORD *ExceptionRecord,
void *EstablisherFrame,
struct _CONTEXT *ContextRecord,
struct _DISPATCHER_CONTEXT *DispatcherContext);
WindowsException();
};
class AccessViolation : public WindowsException {
};
WindowsException::WindowsException(struct _EXCEPTION_RECORD *ExceptionRecord,
void *EstablisherFrame,
struct _CONTEXT *ContextRecord,
struct _DISPATCHER_CONTEXT *DispatcherContext)
{
this->ExceptionRecord = ExceptionRecord;
this->EstablisherFrame = EstablisherFrame;
this->ContextRecord = ContextRecord;
this->DispatcherContext = DispatcherContext;
static char msg[512];
static wchar_t wmsg[512];
snprintf(msg, sizeof(msg), "WindowsException(%p, %p, %p, %p)\r\n"
"Code %x Flags %p Address %p",
ExceptionRecord, EstablisherFrame, ContextRecord, DispatcherContext,
ExceptionRecord->ExceptionCode,
ExceptionRecord->ExceptionFlags,
ExceptionRecord->ExceptionAddress);
mbstowcs(wmsg, msg, strlen(msg)+1);
MessageBoxW(0, wmsg, L"WindowsException", 0);
exit(0);
}
int i, *p;
void Handle(struct _EXCEPTION_RECORD *ExceptionRecord,
void *EstablisherFrame,
struct _CONTEXT *ContextRecord,
struct _DISPATCHER_CONTEXT *DispatcherContext)
{
throw WindowsException(ExceptionRecord, EstablisherFrame, ContextRecord, DispatcherContext);
}
main()
{
CegccSetExceptionHandler(Handle);
p = 0;
*p = 123; /* Crash */
Message("Main", "got to the end");
}
signature.asc
Description: This is a digitally signed message part
------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/
_______________________________________________ Cegcc-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/cegcc-devel
