KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q241706: BUG: Compiler Error C2143 on Function-Try-Block Syntax

Article: Q241706
Product(s): Microsoft C Compiler
Version(s): winnt:6.0
Operating System(s): 
Keyword(s): kbCompiler kbCPPonly kbLangCPP kbVC600 kbVC600bug
Last Modified: 03-MAY-2001

-------------------------------------------------------------------------------
The information in this article applies to:

- The C/C++ Compiler (CL.EXE), included with:
   - Microsoft Visual C++, 32-bit Enterprise Edition, version 6.0 
   - Microsoft Visual C++, 32-bit Professional Edition, version 6.0 
   - Microsoft Visual C++, 32-bit Learning Edition, version 6.0 
-------------------------------------------------------------------------------

SYMPTOMS
========

The following error messages may appear if you try to use the function-try-block
syntax.

  error C2143: syntax error : missing ';' before 'try'
  error C2143: syntax error : missing ';' before 'try'
  error C2065: 'ii' : undeclared identifier
  error C2143: syntax error : missing ';' before 'try'
  error C2448: 'Unknown' : function-style initializer appears to be a function
  definition
  error C2143: syntax error : missing ';' before 'catch'
  error C2143: syntax error : missing ';' before '{'
  error C2447: missing function header (old-style formal list?)

CAUSE
=====

The compiler does not support the function-try-block syntax as specified in the
C++ Standard (section 15) quoted below:

  -3- A function-try-block associates a handler-seq with the ctor-initializer,
  if present, and the function-body. An exception thrown during the execution
  of the initializer expressions in the ctor-initializer or during the
  execution of the function-body transfers control to a handler in a
  function-try-block in the same way as an exception thrown during the
  execution of a try-block transfers control to other handler.

STATUS
======

Microsoft has confirmed this to be a bug in the Microsoft products listed at the
beginning of this article.

MORE INFORMATION
================

Steps to Reproduce Behavior
---------------------------

The following code example demonstrates the error:

  //test.cpp
  // compiler option needed: /GX
  int f(int);
  class C {
  	int i;
  public:
  	C(int);
  };

  C::C(int ii)
  try
  : i(f(ii))
  {
  	//  constructor function body
  }
  catch (...)
  {
  	//  handles exceptions thrown from the ctor-initializer
  	//  and from the constructor function body
  }

Additional query words:

======================================================================
Keywords          : kbCompiler kbCPPonly kbLangCPP kbVC600 kbVC600bug 
Technology        : kbVCsearch kbAudDeveloper kbCVCComp
Version           : winnt:6.0
Issue type        : kbbug

=============================================================================

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.

Copyright Microsoft Corporation 1986-2002.