* Tony:
That doesn't sound correct at all.
I'll try to explain, then.
The purpose of a constructor in C++ is to couple allocation and
initialization in one all-or-nothing operation, a transaction.
After a constructor call you either have an initialized object at hand,
or an exception.
In the case of an exception, if the constructor was invoked via new, the
allocated memory has been automatically deallocated: construction is an
all-or-nothing operation, either allocation+initialization, or nothing.
If you remove exceptions, first of all the all-or-nothing functionality
is removed -- you can and will then have improperly initialized
objects accessible -- which defeats the very purpose of constructors.
Second, to be able to handle initialization failure dialects such as
Symbian C++ require the programmer to use two-phase construction where
the "C++" constructor is just a dummy, with an initialization member
function called afterwards by the client code. And with that technique
not only is the purpose of the constructor defeated, but the constructor
has become just a hindrance that must be overcome by some alternative
initialization scheme. Constructors then just add complexity, no gain.
Consider if, in such a thwarted dialect of "C++", a class Base
constructor fails when called automatically from a class Derived
constructor. Perhaps class Derived has some members of type Mambo. To
signal its failure the Base constructor sets the boolean member
'okSoFar' to false. But since that's a scheme the compiler knows
nothing about, the Mambo members are now automatically constructed,
perhaps causing some side-effects such as windows popping up. Now the
Derived constructor's body is executed and it detectes the failed Base
construction, and must communicate that to the client code, somehow...
Constructor + copy constructor +
destructor
+ assignment operator allow creation of objects that act like built-in
types.
Sort of.
Without exceptions you're limited to types where initialization can't
fail, and/or treating all failures as fatal errors, and/or using the
language in a way ignoring constructors.
This was useful enough that C++ enjoyed a fair degree of success without
exceptions, up till the late 1980's, as a "better C", but the section on
error handling in the first edition of TCPPPL tellingly lists the then
current alternatives and finds fault with them all for ordinary function
calls, without even discussing how to handle failure in constructors.
Exceptions just solve the problem of how to handle errors in those
functions.
No, that problem is not a problem that can be solved by other known means.
Constructors weren't created as a result of exception handling, EH was
created as a result of constructors.
No, that's incorrect. Exceptions were adopted late in the
standardization process, that's true. But first, they weren't invented
to support constructors, nor vice versa, and second, they weren't
invented in C++. Experience with exceptions had been gained from Ada
and other languages, as well as at a low level in e.g. Windows NT. They
fitted the requirements of constructors, and no other scheme did.