如果我用“goto”跳出 catch 块,我是否能保证异常对象将被释放?
我有如下代码
try {
doSomething();
} catch(InterruptException) {
goto rewind_code;
}
if(0) {
rewind_code:
longjmp(savepoint, 1);
}
我的问题是,当我 goto
脱离 catch 块时,C++ 运行时存储的异常对象是否被释放?或者运行时是否允许缓存它,直到周围的函数存在或类似的东西?我只是想确保,如果我多次执行上述代码,每次执行倒带代码时,我都不会泄漏内存(因为 longjmp
不会执行编译器发出的清理代码到或在函数序言之前)。
I have such code as follows
try {
doSomething();
} catch(InterruptException) {
goto rewind_code;
}
if(0) {
rewind_code:
longjmp(savepoint, 1);
}
My question is, is the exception object that is stored by the C++ runtime free'ed when I goto
out of the catch block? Or is the runtime allowed to cache it until the surrounding function exists or something like that? I simply want to ensure that if I execute above code multiple times, each time taking the rewind code, I won't leak memory (because the longjmp
won't execute cleanup code emitted by the compiler into or before function prologues).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
§6.6/2:
至少在我读到的时候,“无论如何完成”应该/确实包含一个 goto< /代码>。
编辑:好的,根据 Johannes 的评论,我们关心的是 §15.1/4:
[...]
§6.6/2:
At least as I'd read it, "however accomplished" should/does include a
goto
.Edit: Okay, based on Johannes's comment, what we care about is §15.1/4:
[ ... ]
§15.1.4
§ 15.1.4