PRB: C2060 or C1004 Error Occurs Using TRY/CATCH Macros (93447)



The information in this article applies to:

  • Microsoft Visual C++ for Windows, 16-bit edition 1.0
  • Microsoft Visual C++ for Windows, 16-bit edition 1.5
  • Microsoft Visual C++ for Windows, 16-bit edition 1.51
  • Microsoft Visual C++, 32-bit Editions 1.0
  • Microsoft Visual C++, 32-bit Editions 2.0
  • Microsoft Visual C++, 32-bit Editions 2.1
  • Microsoft Visual C++, 32-bit Editions 4.0
  • Microsoft Visual C++, 32-bit Editions 4.1
  • Microsoft Visual C++, 32-bit Editions 4.2
  • Microsoft Visual C++, 32-bit Editions 5.0

This article was previously published under Q93447

SYMPTOMS

When compiling a C++ program that uses the TRY and CATCH macros to implement exception handling, the compilation fails with the following error message:
error C2060: syntax error : end-of-file found
With Visual C++ 32-bit Edition, the following error is generated:
fatal error C1004: unexpected end of file found

CAUSE

A CATCH (or AND_CATCH) block is not closed with the END_CATCH macro. The CATCH macro creates a code block that is to be terminated by the END_CATCH macro.

RESOLUTION

Modify the program code to add the END_CATCH macro to the exception handling code.

MORE INFORMATION

Sample Code

/* Compile option needed: none if source file given .cpp extension,
   /Tp otherwise.
*/ 

#include <afx.h>
#include <afxwin.h>

void main(void)
{
   TRY
   {
   }
   CATCH(CFileException,e)
   {
   }
   // Uncomment following line for successful compilation
   //END_CATCH
}
				

Modification Type:MinorLast Reviewed:7/5/2005
Keywords:kbCompiler kbprb KB93447