try catch使用示例

DWORD CIec61850Server::IECServerThread(PVOID pArg)
{
    CIec61850Server *pDlg = (CIec61850Server *)pArg;
    DWORD result = 0;
    while(1)
    {
        result = WaitForSingleObject(pDlg->m_hEvent, 0);
        if (WAIT_OBJECT_0 == result)
        {
            break;
        }
        try
        {
            pDlg->m_Iec61850->Loop();
        }
        catch (CMemoryException* e)
        {
            pDlg->PrintEventMsg(e);
        }
        catch (CException* e)
        {
            pDlg->PrintEventMsg(e);
        }
    }
    return 0;
}

void CIec61850Server::PrintEventMsg(const CException* e )
{
    TCHAR   szCause[255];
    CString strFormatted;

    e->GetErrorMessage(szCause, 255);
    strFormatted.Format(_T("error reaon: %s \n"), szCause);
    TRACE(strFormatted);
}
原文地址:https://www.cnblogs.com/shanwenbin/p/2744213.html