News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

SEH Software eceptions

Started by akko, January 14, 2011, 02:46:17 PM

Previous topic - Next topic

akko

How can I generate software exceptions in Pelles C?

__try { some guarded code }
__except(EXCEPTION_EXECUTE_HANDLER) { some handler code }

void myThrow(int tc)  // called from try block
{  RaiseException((DWORD)tc,0,0,NULL); // ??? does not work
}

TimoVJL

#include <windows.h>
#include <stdio.h>

DWORD exception_filter(int* k)
{
  return EXCEPTION_EXECUTE_HANDLER;
}

void myThrow(int tc)  // called from try block
{
  RaiseException((DWORD)tc,0,0,NULL); //  does not work
}

int main(void)
{
  int               foo = 0;
  __try
  {
    //*(DWORD *) 0 = 0xdeadbeef;
    myThrow(0);
  }
  __except(exception_filter(&foo))
  {
    printf("Exception!\n");
  }
  return 0;
}
May the source be with you

akko