请示范一下TRY的用法

scxy 2001-08-29 02:55:37
...全文
135 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
蒋晟 2001-08-29
  • 打赏
  • 举报
回复
TRY
{
pFile = new CFile(_T("C:\\WINDOWS\\SYSTEM.INI"),
CFile::modeRead | CFile::shareDenyNone);

DWORD dwLength = pFile->GetLength();

CString str;
str.Format(_T("Your SYSTEM.INI file is %u bytes long."),
dwLength);

AfxMessageBox(str);
}
CATCH(CFileException, pEx)
{
// Simply show an error message to the user.

pEx->ReportError();
}
AND_CATCH(CMemoryException, pEx)
{
// We can't recover from this memory exception, so we'll
// just terminate the app without any cleanup. Normally, an
// an application should do everything it possibly can to
// clean up properly and _not_ call AfxAbort().

AfxAbort();
}
END_CATCH

// If an exception occurs in the CFile constructor,
// the language will free the memory allocated by new
// and will not complete the assignment to pFile.
// Thus, our clean-up code needs to test for NULL.

if (pFile != NULL)
{
pFile->Close();
delete pFile;
}
prog_st 2001-08-29
  • 打赏
  • 举报
回复
The following example shows how to examine the contents of a CFileException. Other exception types can be examined similarly.

try
{
// Do something to throw a file exception.
}
catch( CFileException* theException )
{
if( theException->m_cause == CFileException::fileNotFound )
TRACE( "File not found\n" );
theException->Delete();
}

scxy 2001-08-29
  • 打赏
  • 举报
回复
push
scxy 2001-08-29
  • 打赏
  • 举报
回复
请不吝赐教
scxy 2001-08-29
  • 打赏
  • 举报
回复
e在哪儿定义,怎样定义,请别见笑,我很菜,谢谢
ytby 2001-08-29
  • 打赏
  • 举报
回复
TRY
{
}
CATCH_ALL( e )
{
}
END_CATCH_ALL
scxy 2001-08-29
  • 打赏
  • 举报
回复
请各位关注谢谢

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧