CException::GetErrorMessage

virtual BOOL GetErrorMessage(LPTSTR lpszError, UINT nMaxError, PUINT pnHelpContext = NULL);

返回值:
如果函数成功,则返回非零值;如果无错误信息文本,则返回0。

参数:
lpszError获取错误信息的缓冲区指针。
nMaxError缓冲区最多可以容纳的字符数(包括NULL终止符)。
pnHelpContext一个UINT地址,用于接收帮助文本上下文ID;如果为NULL,则不返回ID。

说明:
调用此成员函数提供有关所发生的错误的更多信息文本。例如,获取一个描述产生MFC在写一个CFile对象时出现CFileException异常的字符串。
注意:
此函数会拷贝多于nMaxError-1个字符到缓冲区,通常加一个空字符到结尾。如果缓冲区太小,错误信息将被截取。

示例:
以下是一个使用此成员函数的例子:
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.GetErrorMessage()
// will retrieve an appropriate message describing
// the error, and we'll add our own text
// to make sure the user is perfectly sure what
// went wrong.

if (!fileInput.Open("\\Too\\Many\\Bad\\Dirs.DAT", CFile::modeRead, &ex))
{
  TCHAR szCause[255];
  CString strFormatted;

  ex.GetErrorMessage(szCause, 255);

  // (in real life, it's probably more
  // appropriate to read this from
  // a string resource so it would be easy to
  // localize)

  strFormatted = _T("The data file could not be opened because of this error: ");
  strFormatted += szCause;

  AfxMessageBox(strFormatted);

else
{
  // the file was opened, so do whatever work
  // with fileInput
  // we were planning...
  // :

  fileInput.Close();
}

请参阅:CException::ReportError