gpt4 book ai didi

c++ - catch(...) 中的 throw 是按值还是按引用抛出

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:20:56 24 4
gpt4 key购买 nike

我老板回答了这个问题why ... (three points) in catch block is exist?非常优雅。

但这让我想到了一些事情(并希望弥补我之前的错误问题),确实

catch(...){
throw;
}

通过(即采用深拷贝)或通过引用重新抛出捕获的异常?

最佳答案

标准说:

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:2011 第 15.1 节8

换句话说,它只是用原来的异常对象继续异常传播。我想这类似于您所说的“通过引用”的意思。

关于c++ - catch(...) 中的 throw 是按值还是按引用抛出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36738222/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com