将VC ++的__try / __除了EXCEPTION_STACK_OVERFLOW移植到MinGW [英] Porting VC++'s __try/__except EXCEPTION_STACK_OVERFLOW to MinGW

查看:327
本文介绍了将VC ++的__try / __除了EXCEPTION_STACK_OVERFLOW移植到MinGW的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用VC ++的try-except语句将一些代码移植到MinGW:

I am trying to port some code using VC++'s try-except statement to MinGW:

bool success = true;

__try {
    //...
} __except ((EXCEPTION_STACK_OVERFLOW == GetExceptionCode())
            ? EXCEPTION_EXECUTE_HANDLER
            : EXCEPTION_CONTINUE_SEARCH) {
    success = false;
    _resetstkoflw();
}
return success;

是否可以编写使用MinGW g ++捕获堆栈溢出异常的代码?

Is it possible to write code that catches a stack overflow exception using MinGW g++?

推荐答案

您需要手动调用注册异常处理的Windows API函数;即 AddVectoredExceptionHandler 。注意,通过使用不尊重SEH异常的MinGW,抛出任何SEH异常或试图捕获任何这样的异常将导致未定义的行为,因为没有完成正常的C ++堆栈展开语义。 (Windows如何知道对堆栈上的所有 std :: string 进行nuke?)

You would need to manually call the Windows API functions which register exception handling; namely, AddVectoredExceptionHandler. Note that by using MinGW which does not respect SEH exceptions, throwing any SEH exception or attempting to catch any such exception will result in undefined behavior, because the normal C++ stack unwinding semantic isn't done. (How does Windows know to nuke all those std::strings on the stack?)

需要在您希望调用SEH异常处理程序的时间结束时调用 RemoveVectoredExceptionHandler

You would also need to call RemoveVectoredExceptionHandler at the end of the time you want that SEH exception handler to be called.

一般MinGW缺乏对SEH和COM等Windows功能的支持。任何理由,你试图使用,而不是MSVC ++(因为两个编译器是免费的?)

Generally MinGW is lacking in support of Windows features like SEH and COM. Any reason you're trying to use that instead of MSVC++ (given that both compilers are free?)

这篇关于将VC ++的__try / __除了EXCEPTION_STACK_OVERFLOW移植到MinGW的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆