Walter Bright wrote:
Justin Johansson wrote:
(1) For some reason (possibly valid only in an historic context), I
have this great aversion to throwing exceptions from inside C++
constructors. From memory, I once threw an exception from inside a
constructor
with an early C++ compiler and wound up with stack corruption or
something like that, and consequently I developed the practice of
forever more avoiding throwing from inside a C++ constructor.
I'm a believer in the methodology that a constructor should be "trivial"
in that it cannot fail (i.e. cannot throw). I'm probably in the minority
with that view, but you shouldn't feel like you're doing the wrong thing
when you stick to such a style.
auto x = new BigInt(someString);
How do you implement BigInt's constructor without being able to throw an
exception? Or would you do it like:
auto x = BigInt.fromString(someString);
to be able to throw? (just to obey the "no throw in constructors"... but
that's not as trivial as the previous form)