将VC ++的__try / __除了EXCEPTION_STACK_OVERFLOW移植到MinGW [英] Porting VC++'s __try/__except EXCEPTION_STACK_OVERFLOW to 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::string
s 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屋!