共用方式為


CException::ReportError

呼叫此成員函式在訊息方塊中的錯誤文字會向使用者報告。

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

參數

  • nType
    指定訊息方塊的樣式。 適用於 訊息方塊樣式 任意組合的方塊。 如果沒有指定此參數,則預設值為 MB_OK

  • nMessageID
    指定的資源 ID (資料表項目) 要顯示的訊息,如果例外狀況物件沒有一個錯誤訊息。 如果為 0,訊息「錯誤訊息無法使用」隨即顯示。

傳回值

AfxMessageBox 值;則為 0,如果沒有顯示訊息方塊的足夠的記憶體。 針對可能的傳回值 AfxMessageBox 參閱。

範例

這個範例使用的 CException::ReportError。 如需其他範例,請參閱 catch範例。

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

需求

Header: afx.h

請參閱

參考

CException 類別

階層架構圖

AfxMessageBox

CFileException::GetErrorMessage