Throw exception from initializer list
Posted
by aaa
on Stack Overflow
See other posts from Stack Overflow
or by aaa
Published on 2010-04-20T03:45:56Z
Indexed on
2010/04/20
4:03 UTC
Read the original article
Hit count: 525
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
© Stack Overflow or respective owner