Share via


CException::ReportError

Call this member function to report error text in a message box to the user.

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

Parameters

  • nType
    Specifies the style of the message box. Apply any combination of the message-box styles to the box. If you don't specify this parameter, the default is MB_OK.

  • nMessageID
    Specifies the resource ID (string table entry) of a message to display if the exception object does not have an error message. If 0, the message "No error message is available" is displayed.

Return Value

An AfxMessageBox value; otherwise 0 if there is not enough memory to display the message box. See AfxMessageBox for the possible return values.

Example

Here is an example of the use of CException::ReportError. For another example, see the example for 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();
}

Requirements

Header: afx.h

See Also

Reference

CException Class

Hierarchy Chart

AfxMessageBox

CFileException::GetErrorMessage