Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
C ++では、スローされるオブジェクトのコンストラクター自体が例外をスローすることは有効ですか?言い換えれば、スローするオブジェクトをまだ構築している間、私たちはまだスロー中ですか?
struct Error { Error() { if (someCondition()) { throw anotherObject(); } } }; void test() { throw Error(); }
スロー式はである必要がありますがthrow Error();、はい、これは有効です。
throw Error();
オブジェクトをスローする前に、Errorオブジェクトを作成する必要があります。つまり、演算子を完全な式でError()評価する前に、部分式を評価する必要があります。throw部分式Error()自体の評価が例外をスローした場合、完全な式の残りの部分(つまり、throw)は評価されません。
Error
Error()
throw