[Qt-interest] Constructor initializer exceptions (was: QFile private member)
andrew.m.goth at l-3com.com
andrew.m.goth at l-3com.com
Wed Feb 11 19:06:21 CET 2009
Paul Floyd wrote:
> If you are into exception safety,
Just a reminder: Qt doesn't use C++ exceptions. But your code might,
and you can certainly use other libraries that do. Such as the C++
standard library. ;^)
> MyClass::MyClass(QObject* parent) try :
> QObject(parent),
> file(new QFile(this)
> {}
> catch (...) // or at least std::exception
> {}
I have never seen that syntax before. Is it standard C++? The
following code compiles in gcc 3.4.6:
struct foo {foo(); int x;};
foo::foo() try: x() {} catch (...) {}
But I read that this feature isn't in MS Visual C++ 6, only 7 onwards.
http://weseetips.com/2008/06/04/how-to-catch-exceptions-from-constructor
-initializer-list/
And according to this, the exception is automatically re-thrown when the
catch block finishes, so this construct can't be used to suppress an
exception.
http://www.cprogramming.com/tutorial/initialization-lists-c++.html
--
Andy Goth
<amgoth at link.com>
More information about the Qt-interest-old
mailing list