GeniusOfEvil’s Blog

It is a sin to believe evil of others, but it is seldom a mistake.

Posts Tagged ‘Cpp

Exception handling in constructor’s initialization list

There are some aspects of C++ syntax that still amaze me… The syntax for catching an exception in an initialization list is one of them.It’s totally awkward

class MyClass {
public:
     MyClass()
     try : <initialization list>
     { }
     catch ( ... ) { 
     }
};

But even if you catch the exception, you are pretty much screw because it cannot be guaranteed that object being created is in a valid state.There’s nothing much you can do besides rethrowing the exception.

Written by Jarek Przygódzki

April 1, 2009 at 2:43 pm

Posted in C++, Cpp, Programing

Tagged with , ,