非const参照によってスタック上に構築されたオブジェクトをtry-blockにスローし、それをキャッチして変更してから、別のcatchブロックを参照してスローすることに問題はありますか?
以下は私が参照しているものの短い例です。
struct EC {
EC(string msg) { what = msg; }
string where;
string what;
void app(string& t) { where += t; }
string get() { return what; }
};
try {
try {
try {
EC error("Test");
throw error;
}
catch (EC& e) {
e.app("1");
throw e;
}
}
catch (EC& e) {
e.app("2");
throw e;
}
}
catch (EC& e) {
e.app("3");
cout << e.where << endl;
cout << e.get() << endl;
}
これにより、e。何にジャンクが含まれる可能性がありますが、e。どこにそのまま残る可能性がありますか?例:
e.where is "123"
e.get()は、ヌルバイトに到達するまで、大量のガベージデータを返します。