Windows异常处理实例代码

几句代码做点记录...

之前在编程的时候有时会碰到内存访问错误,然后我加入了try...catch...可捕捉不到异常,

原来try...catch...是C++的异常捕捉方式,和windows的异常处理_try...__except...有区别,具体在这里就不写了,网上有很多答案。

下面贴上_try...__except...示例代码:

long WINAPI FilterFunc(DWORD dwExceptionCode)
{
 return (dwExceptionCode == STATUS_ACCESS_VIOLATION) ? EXCEPTION_EXECUTE_HANDLER : EXCEPTION_CONTINUE_SEARCH;
}

bool CPlayerDlg::Play_Frame(char* pSrc, DWORD dwLen, char* pDecodeBuf, int iSide)
{
 __try
 {
   ...
 }
 __except (FilterFunc(GetExceptionCode()))
 {
  outputdebugstring("memory error ocurred!");
  return false;
 }

 return true;
}

 

你可能感兴趣的:(Windows异常处理实例代码)