【发布时间】:2010-09-23 16:59:54
【问题描述】:
我在我的程序中遇到了这个异常:
在 0x0051cce0 处未处理的异常 JSONDataParsing.exe:0xC0000005: 访问冲突读取位置 0x00000004
.
我尝试捕获异常,但没有用。我知道问题出在哪里。但想知道如何捕获异常。我在发生异常的代码周围使用了 try、catch 块。
这是一个无法捕获的异常吗?
catch 语句是:
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();
}
【问题讨论】:
-
请向我们展示您的
catch声明 -
catch (...)有效吗?另请查看What should I know about Structured Exceptions (SEH) in C++?