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

ID: Q93447


The information in this article applies to:
  • The Microsoft C/C++ Compiler (CL.EXE)
    • Microsoft C/C++ for MS-DOS, version 7.0
    • Microsoft Visual C++ for Windows, 16-bit edition, versions 1.0, 1.5, 1.51
    • Microsoft Visual C++, 32-bit Editions, versions 1.0, 2.0, 2.1, 4.0, 4.1, 4.2, 5.0


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
} 

Additional query words: 8.00 8.00c 9.00 9.10

Keywords : kbCompiler kbVC100 kbVC151 kbVC200 kbVC210 kbVC400 kbVC410 kbVC420 kbVC500
Version : MS-DOS:7.0;WINDOWS:1.0;1.5;1.51;WINDOWS NT:1.0,2.0,2.1,4.0,4.1,4.2,5.0
Platform :
Issue type : kbprb


Last Reviewed: July 6, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.