NO

Author Topic: SEH Software eceptions  (Read 3659 times)

akko

  • Guest
SEH Software eceptions
« 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
}

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2115
Re: SEH Software eceptions
« Reply #1 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;
}
May the source be with you

akko

  • Guest
Re: SEH Software eceptions
« Reply #2 on: January 15, 2011, 05:56:35 PM »
Thanks Timovjl, it works!  :)