This documentation is archived and is not being maintained.

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
      f(ii) ;
      // body of function goes in try block
   catch (...) {
      // handles exceptions thrown from the constructor-initializer
      // and from the constructor function body
      printf_s("In the catch block\n");

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


In the catch block