问题
Is it possible to catch unhandle exception in C++/CX? I found that if crash happened in C++/CX my app will terminate immediately (Application_UnhandledException not get called). What's more, I found Win32 api SetUnhandledExceptionFilter is not avaliable which is Windows API for catching unhandle exception.
回答1:
If by exception you mean structured exceptions, you probably should use __try, e.g. something like this (untested code below):
__try
{
someCode();
}
__except( EXCEPTION_EXECUTE_HANDLER )
{
throw Platform::Exception::CreateException( ... );
}
Or, if you're trying to handle a C++ exception, such as exceptions from STL, then you should catch them with try-catch statement, and throw Platform::Exception instead - this way they'll be correctly marshaled back into the managed code.
来源:https://stackoverflow.com/questions/21274063/catching-unhandle-exception-in-c-cx