MFC中异常的处理
我在程序中遇到了以下异常: 中0x0051cce0处未处理的异常 JSONDataParsing.exe:0xC0000005: 访问冲突读取位置 0x00000004 我试图捕捉异常,但没有用。我知道问题发生在哪里。但我想知道如何捕获异常。我在发生异常的代码周围使用了try,catch块 这是否一个无法捕捉的例外情况 catch语句是:MFC中异常的处理,mfc,exception-handling,Mfc,Exception Handling,我在程序中遇到了以下异常: 中0x0051cce0处未处理的异常 JSONDataParsing.exe:0xC0000005: 访问冲突读取位置 0x00000004 我试图捕捉异常,但没有用。我知道问题发生在哪里。但我想知道如何捕获异常。我在发生异常的代码周围使用了try,catch块 这是否一个无法捕捉的例外情况 catch语句是: catch (bad_alloc&) { TCHAR msgbuf[MAX_PATH];
catch (bad_alloc&)
{
TCHAR msgbuf[MAX_PATH];
swprintf(msgbuf, L"bad_alloc \n");
OutputDebugString(msgbuf);
}
catch (bad_cast&)
{
TCHAR msgbuf[MAX_PATH];
swprintf(msgbuf, L"bad_cast \n");
OutputDebugString(msgbuf);
}
catch (bad_exception&)
{
TCHAR msgbuf[MAX_PATH];
swprintf(msgbuf, L"babad_exceptiond_alloc \n");
OutputDebugString(msgbuf);
}
catch (bad_typeid&)
{
TCHAR msgbuf[MAX_PATH];
swprintf(msgbuf, L"bad_alloc \n");
OutputDebugString(msgbuf);
}
catch( CMemoryException* e )
{
TCHAR msgbuf[MAX_PATH];
swprintf(msgbuf, L"CMemoryException \n");
OutputDebugString(msgbuf);
// Handle the out-of-memory exception here.
}
catch( CFileException* e )
{
TCHAR msgbuf[MAX_PATH];
swprintf(msgbuf, L"CFileException \n");
OutputDebugString(msgbuf);
// Handle the file exceptions here.
}
catch( CException* e )
{
TCHAR msgbuf[MAX_PATH];
swprintf(msgbuf, L"CException \n");
OutputDebugString(msgbuf);
// Handle the exception here.
// "e" contains information about the exception.
e->Delete();
}
您只能使用特殊的try-catch处理程序捕获此类异常:
try
{
// code that triggers such an exception. for example:
int * a = NULL;
*a = 0;
}
catch (...)
{
// now that exception is handled here
}
但一般来说,这样做是不好的做法。相反,您不应该得到这样的异常,而应该检查您的参数和变量
有关更多详细信息,请参见此处:
您只能使用特殊的try-catch处理程序捕获此类异常:
try
{
// code that triggers such an exception. for example:
int * a = NULL;
*a = 0;
}
catch (...)
{
// now that exception is handled here
}
但一般来说,这样做是不好的做法。相反,您不应该得到这样的异常,而应该检查您的参数和变量
有关更多详细信息,请参见此处:
可以使用uu try-except语句捕获这种类型的低级异常,但您应该修复它的原因,而不是报告它。在VS中,调试时按CTRL+ALT+E并检查所有异常,然后继续运行应用程序,直到出现异常。提示将在出现问题的行上停止。 看见
有关详细信息。可以使用u try-except语句捕获此类低级异常,但您应该修复其原因,而不是报告它。在VS中,调试时按CTRL+ALT+E并检查所有异常,然后继续运行应用程序,直到出现异常。提示将在出现问题的行上停止。 看见
有关详细信息。请向我们展示您的
catch
声明catch(…)
有效吗?另外,请查看您的catch
声明catch(…)
有效吗?另外,请检查Hi Stefan,我使用了此选项,无法捕获访问冲突。您必须使用/EHa标志进行编译Hi Stefan,我使用了此选项,无法捕获访问冲突。您必须使用/EHa标志进行编译