gpt4 book ai didi

c++ - 这个声明是什么意思?异常()抛出()

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:50:17 25 4
gpt4 key购买 nike

std::exception类定义如下

exception() throw() { }
virtual ~exception() throw();
virtual const char* what() const throw();

声明中的 throw() 语法是什么意思?throw() 可以带参数吗?没有参数是什么意思?

最佳答案

这是一个“异常规范”。 throw() 意思是“这个函数不会抛出任何异常”。您还可以指定异常,因此 throw(foo) 会说此函数可能会抛出 foo 类型的异常。

这个特性的好用性在C++社区中争论不休——普遍的评价似乎是它不是特别好用。有关详细信息,请查看 this Herb Sutter article .

关于c++ - 这个声明是什么意思?异常()抛出(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41660561/

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