开发者

Windows Structured Exception Handling: simple test program will not compile

开发者 https://www.devze.com 2023-01-03 13:22 出处:网络
#include <windows.h> int main() { int* i = (int*)malloc(sizeof(int)); *i = 5; __try { 开发者_StackOverflow中文版free(i);
#include <windows.h>

int main()
{

    int* i = (int*)malloc(sizeof(int));
    *i = 5;

    __try
    {
    开发者_StackOverflow中文版    free(i);
        free(i);
    }
    __except
    {
        return -1;
    }


return 0;
}

I am trying to learn more about windows SEH. My first test program is giving me some real trouble. I have looked at the msdn documentation and I am still not really sure what I have wrong. I am getting the following errors when I try to compile this program:

error C2059: syntax error : '{'
error C2143: syntax error : missing ';' before '{'

both on line 15.

Thanks.


The problem is the __except clause needs to have an expression. See the following MSDN page for a complete sample

http://msdn.microsoft.com/en-us/library/aa273608(VS.60).aspx

Quick example which will always execute the handler

__try {
  // stuff
} __except (EXCEPTION_EXECUTE_HANDLER) {
  // handler
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号