抛出的catch(...)抛出的值或引用 [英] Does a throw in catch(...) throw by value or by reference
问题描述
我的老板回答了这个问题为什么... (三分)在catch块中存在?非常优雅。
My boss answered this question why ... (three points) in catch block is exist? quite elegantly.
但它使我想到了一些东西(希望弥补我以前的坏问题) ,
But it's made me think of something (and hopefully makes up for my previous bad question), does
catch(...){
throw;
}
通过值重新抛出捕获的异常
rethrow the caught exception by value (i.e. a deep copy is taken), or by reference?
推荐答案
标准说:
没有操作数的throw-expression会重新抛出当前处理的异常。例外被重新激活与现有的临时;没有新的临时异常对象被创建。
A throw-expression with no operand rethrows the currently handled exception. The exception is reactivated with the existing temporary; no new temporary exception object is created.
- ISO / IEC 14882: 8
换句话说,它只是使用原始异常对象继续异常传播。我想这是类似于你的意思是通过参考。
In other words, it simply continues the exception propagation with the original exception object. I suppose this is analogous to what you mean by "by reference".
这篇关于抛出的catch(...)抛出的值或引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!