Throw exception from initializer list
- by aaa
hello.
what is the best way to throw exception from initializer list?
for example:
class C {
T0 t0; // can be either valid or invalid, but does not throw directly
T1 t1; // heavy object, do not construct if t0 is invalid, by throwing before
C(int n)
: t0(n), // throw exception if t0(n) is not valid
t1() {}
};
I thought maybe making wrapper, e.g. t0(throw_if_invalid(n)).
What is the practice to handle such cases?
Thanks