[Interest] Where to catch exception when a qml plugin is loaded? Even possible?

Stephen Bryant steve at bawue.de
Thu Apr 26 10:23:45 CEST 2012


Hi,

> Naaaa, throwing from a constructor is fine. Throwing from a destructor
> is a big no no. Actually there is no other way to cleanly 'get out'
> when construction fails.

Ooohh...  big disagreement coming up here!!

Consider this line:

   Foo *foo = new Foo();

Assuming 'new' succeeds and allocates memory on the heap: if the constructor 
throws, the pointer 'foo' never gets initialised.

How do you cleanly 'get out' of that one?  I.e. how do you delete the 
allocated memory without knowing where it is?  If someone has a solution for 
this, I'll happily change my position!

My opinion is that it is a question of design, and that any initialisation 
which throws on error must be performed post-construction in a separate step, 
such as foo->init() or so.

Going back to Den's original post, that means he'd need to add an init method 
to ImageModel, and make sure it gets called when he wants to use the object.

Steve
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20120426/cd46f2b7/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20120426/cd46f2b7/attachment.sig>


More information about the Interest mailing list