Condividi tramite


CFileException::GetErrorMessage

Recupera il testo che viene descritta un'eccezione.

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

Parametri

  • [in, out] lpszError
    Puntatore a un buffer che riceve un messaggio di errore.

  • [in] nMaxError
    Il numero massimo di caratteri dal buffer specificato potrebbe utilizzare.Ciò include il carattere di terminazione null.

  • [in, out] pnHelpContext
    Puntatore in Unsigned Integer che riceve l'id del contesto della guidaSe NULLID, non viene restituito.

Valore restituito

TRUE se il metodo è riuscita, in caso contrario FALSE.

Note

Se il buffer specificato è troppo piccolo, il messaggio di errore viene troncato.

Esempio

Nell'esempio seguente viene utilizzata l'interfaccia 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();
}

Requisiti

intestazione: afx.h

Vedere anche

Riferimenti

Classe di CException

Grafico della gerarchia

CException::ReportError