CException::ReportError

virtual int ReportError(UINT nType = MB_OK, UINT nMessageID = 0);

返回值:
一个AfxMessage值。如果没有足够的内存来显示消息框,则返回0。请参阅AfxMessageBox,了解可能的返回值。

参数:
nType指定消息框的风格。把消息框风格应用在框上。如果不指定此参数,缺省为MB_OK。
nMessageID如果异常对象没有错误消息,指定要显示的消息资源的ID(字符串表入口)。如果为0,显示“没有可用的错误消息”。

说明:
调用此成员函数在消息框中向用户报告出错文本。

示例:
以下是一个使用此函数的例子:
CFile fileInput;
CFileException ex;

// try to open a file for reading.
// The file will certainly not
// exist because there are too many explicit
// directories in the name.

// if the call to Open() fails, ex will be
// initialized with exception
// information. the call to ex.ReportError() will
// display an appropriate
// error message to the user, such as
// "\Too\Many\Bad\Dirs.DAT contains an
// invalid path." The error message text will be
// appropriate for the
// file name and error condition.

if (!fileInput.Open("\\Too\\Many\\Bad\\Dirs.DAT", CFile::modeRead, &ex))
{
   ex.ReportError();
}
else
{
   // the file was opened, so do whatever work
   // with fileInput we were planning...
   // :

   fileInput.Close();
}

请参阅:AfxMessageBox, CException::GetErrorMessage