Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Collapse the table of content
Expand the table of content


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 



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.


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.

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

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("\\Too\\Many\\Bad\\Dirs.DAT", CFile::modeRead, &ex))
      // the file was opened, so do whatever work
      // with fileInput we were planning...
      // :


Community Additions

© 2015 Microsoft