CFileException::GetErrorMessage

擷取描述例外狀況的文字。

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

參數

  • [in, out] lpszError
    會出現錯誤訊息之緩衝區的指標。

  • [in] nMaxError
    指定的緩衝區可以容納的最大字元數。這包括結束的 null 字元。

  • [in, out] pnHelpContext
    out 接收說明主題代碼 . 的不帶正負號整數的指標。如果 NULL沒有 ID,則傳回。

傳回值

TRUE ,如果方法成功,否則 FALSE。

備註

如果指定的緩衝區太小,錯誤訊息會被截斷。

範例

下列的範例會使用 CFileException::GetErrorMessage

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(_T("\\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();
}

需求

標題: afx.h

請參閱

參考

CException 類別

階層架構圖

CException::ReportError