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-11 13:00

>>76
Why the fuck is this so hard to understand? Languages like Java or Python include stack traces, and these are available in a portable way inside the application itself.
You're comparing apples to oranges. C++ is a static language.
One is inside a VM which, like I said, provides a debugger. The other is a dynamic, interpreted (or byte-code compiled) language which also provides a debugger.

C++ could have done this. It could have been a requirement of the standard.
Why is this so hard to understand?

It could include that but then no compiler would've implemented it. Platform independent stack traces so close to the metal are hard to do right.

Wow, this is some terrible exceptions advice. You are *always* supposed to subclass std::exception to create your own exceptions. You can't get away from built-in exceptions without getting rid of the entire STL (and replacing new so that it doesn't throw).
Yes, except no, you are wrong. From the C++ FAQ Lite, 17.6:
If possible, you should throw instances of classes that derive (ultimately) from the std::exception class.

You mean, if you choose either STL or custom exceptions and hope every library you use does the same? Isn't this the very opposite of what you just said?
What I meant is that with the try/catch mechanism you can catch both. When programming in C you have to implement some kind of replacement try/catch for error handling and interface with custom error handling procedures of your libraries.

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