Why following "try catch" cannot catch this OlEDB error (Access database file m_szDataFile is not exist, it will fail at "m_datSpeed.MoveNext();")?  The whole application will halt.try {
    m_datSpeed.Open(m_szDataFile);
    m_datSpeed.MoveNext();
    m_datSpeed.m_session.Close();
    m_datSpeed.Close();
} catch (...) {
    AfxMessageBox("Connect to OLEDB error");
    m_datSpeed.m_session.Close();
    m_datSpeed.Close();
}Here CSpeedData is class CSpeedData : public CCommand<CAccessor<CSpeedDataAccessor>>

解决方案 »

  1.   

    catch ( _com_error &e )
    {
    _bstr_t bstrSource (e.Source());
    _bstr_t bstrDescription (e.Description());
    CString strError;
    strError.Format("无法连接Sybase数据库。\r\n错误代码是:%08lx\r\n错误的原因是:%s\r\n错误源是:%s\r\n错误的描述是:%s\r\n", e.Error (), e.ErrorMessage (), (LPCTSTR) bstrSource, (LPCTSTR) bstrDescription);
    MessageBox (strError, bstrDescription,MB_OK);
    return false;
    }
    catch(CException &e)
    {
    e.ReportError();
    e.Delete();
    return false;
    }
    catch (...)
    {
    TRACE ( "*** 无法解决的错误 ***" );
    return false;
    }
      

  2.   

    It is still not working. Actually catch (...) should catch any other errors.Should I change some setup for this application?
      

  3.   

    没办法,好像只能用failed宏判断下,一旦open failed,就千万别move了,不然会死掉