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

Last reviewed: August 8, 1997
Article ID: Q93447
The information in this article applies to:
  • The Microsoft C/C++ Compiler (CL.EXE) included with: - Microsoft C/C++ for MS-DOS, version 7.0 - Microsoft Visual C++ for Windows, versions 1.0, 1.5, 1.51 - Microsoft Visual C++ 32-bit Edition, 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 : CLIss
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
Issue type : kbprb


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 8, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.