Pelles C forum

C language => Expert questions => Topic started by: akko on January 14, 2011, 02:46:17 PM

Title: SEH Software eceptions
Post by: akko on January 14, 2011, 02:46:17 PM
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
}
Title: Re: SEH Software eceptions
Post by: TimoVJL on January 14, 2011, 03:51:32 PM
Code: [Select]
#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;
}
Title: Re: SEH Software eceptions
Post by: akko on January 15, 2011, 05:56:35 PM
Thanks Timovjl, it works!  :)