Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

C++, "canceling a construction"

Name: Anonymous 2009-11-04 15:25

Hi /prog/

My is simple, but perhaps not so frequent.

How should I stop a construction of an object (c++)?

Basically I have a class with some data members which must fulfill some requirements. Say we initialize these data members upon construction, if the supplied values were erroneous then I guess I want to stop construction and throw an error. Is this the right idea? How do I "cancel the construction"?

Help much appreciated :)

Name: Anonymous 2009-11-04 21:33

>>1
Say we initialize these data members upon construction, if the supplied values were erroneous then I guess I want to stop construction and throw an error. Is this the right idea?
No. You should abort(). Let whatever fucker is using your code know that you won't tolerate his bullshit.

You should never attempt to recover from 'stupid programmer' errors; the louder you make it complain, the quicker the bug will be fixed, and vice versa.

In general, if you need to signal constructor failure for a valid reason which the app might reasonably encounter in the real world and from which it can recover, you should throw. An example is if it needs to open a file that doesn't exist. But never litter your code with throw statements for stupid bullshit. Every throw statement in the app is a massive maintenance and audit headache.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List