Archive for the ‘C++’ Category
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.
Mixing stdio with iostream
When mixing C stdio and C++ iostream synchronization problems can occur because the two libraries use different buffering strategies. This seems a major drawback since mixing C++ code with C libraries (that uses stdio) is a very common practice. Luckily, all we have to do to avoid these problems is to call function
ios::sync_with_stdio()