Search code examples
c++cvisual-c++seh

C/C++ SEH Example build failure


I am complete unfamiliar with c/c++. I need to compile a small program to do some analysis.

This is the program

  #include<stdio.h>
#include<string.h>
#include<windows.h>
//#include<seh.h>
#include<excpt.h>

int ExceptionHandler(void);
int main(int argc,char *argv[])
{

char temp[512];

printf("Application launched");

 try 
     {

    strcpy(temp,argv[1]);

    } catch ( ExceptionHandler() )
    {
    }
return 0;
}
int ExceptionHandler(void)
{
printf("Exception");
return 0;
}

I am compiling on Dev C++ 4.9.9.2. These are the errors I get

   Compiler: Default compiler
Building Makefile: "C:\Documents and Settings\madhur\Desktop\Makefile.win"
Executing  make...
make.exe -f "C:\Documents and Settings\madhur\Desktop\Makefile.win" all
g++.exe -c main.c -o main.o -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include"  -I"C:/Dev-Cpp/include/c++/3.4.2/backward"  -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32"  -I"C:/Dev-Cpp/include/c++/3.4.2"  -I"C:/Dev-Cpp/include"   
main.c: In function `int main(int, char**)':
main.c:20: error: `ExceptionHandler' is not a type
m    ain.c:20: error: invalid catch parameter
make.exe: *** [main.o] Error 1
Execution terminated

Any idea what's so wrong with this code ?


Solution

  • As @Ajay has pointed out SEH is a feature of the Microsoft C/C++ compiler. So there is little luck in using it with GCC (unless you use some addon support - see my comment at his answer about libSEH - mind you I have not personally used it).

    If there is no requirement to use GCC or Dev C++, you could try using the free Microsoft Visual C++ Express edition instead.