Thursday, November 25, 2010

Try-Catch Block around MIL

A try-catch block can be wrapped around a constructor's member initialization list (MIL).

Here is an example of the syntax:

C::C()
   try
   :
   d_b(0)
   {
      // No exception
   } catch(...) {
      // Exception
   }

This is an example of the function try-catch block. I did not find it useful for constructors. It seems even if you catch the exception from d_b's constructor, your program is going to seg-fault using the Sun compiler and abort using the gnu compiler. The gnu compiler lets you do some work first in the catch block before it aborts you. With the gnu compiler on cywin, I was able to print out a message before being aborted.

Reference: http://www.cygwin.com
Cygwin has a free unix environment for Windows, that includes the gnu compiler, Perl and a lot of other utilities.

No comments:

Post a Comment