0

我对 c/c++ 完全不熟悉。我需要编译一个小程序来做一些分析。

这是程序

  #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;
}

我在 Dev C++ 4.9.9.2 上编译。这些是我得到的错误

   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

知道这段代码有什么问题吗?

4

3 回答 3

2

正如@Ajay 所指出的,SEH 是 Microsoft C/C++ 编译器的一项功能。因此,将它与 GCC 一起使用几乎没有运气(除非您使用一些插件支持 - 请参阅我在他关于libSEH的回答中的评论 - 请注意,我没有亲自使用它)。

如果不需要使用 GCC 或 Dev C++,您可以尝试使用免费的Microsoft Visual C++ Express版本。

于 2011-08-09T04:26:51.673 回答
1

__try并且__except是用于 SEH(结构化异常处理)的 Microsoft C/C++ 特定关键字。您应该使用trycatchC++ 异常处理。

于 2011-08-09T04:12:56.247 回答
0

您需要包含seh.h这些内容才能定义。

于 2011-08-09T04:10:36.217 回答