다음을 통해 공유


CFileException::GetErrorMessage

예외를 설명 하는 텍스트를 검색 합니다.

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

매개 변수

  • [in, out]lpszError
    오류 메시지가 발생 하는 버퍼에 대 한 포인터입니다.

  • [in] nMaxError
    최대 문자를 지정 된 버퍼에 저장할 수 있습니다.종료 null 문자를 포함 합니다.

  • [in, out]pnHelpContext
    포인터는 부호 없는 정수 도움말 컨텍스트 ID를 받습니다.경우 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