This documentation is archived and is not being maintained.

Function-try Blocks

In Visual C++ .NET, the compiler supports function-try blocks. A function-try block catches exceptions generated from a call made in a constructor's initialization list.

The following sample uses a function-try block:

// exceptions_Function-tryBlocks.cpp
// compile with: /EHsc
#include "stdio.h"
int f(int i)
   throw "test";
   return 0;

class C 
   int i;

C::C(int ii)
try   // function-try block
: i(f(ii))
   // body of function goes in try block
catch (...)
   // handles exceptions thrown from the constructor-initializer
   // and from the constructor function body
   printf("\nIn the catch block");

int main()
   C *MyC = new C(0);

See Also

C++ Exception Handling | The try, catch, and throw Statements