c++ - 在包含 std::string 的函数上使用 throw() 后缀是否安全?

标签 c++ exception exception-handling std stdstring

我有一个不抛出任何异常的成员函数,所以我在它的末尾附加了 throw() 后缀,表明它不会抛出任何异常。

我的问题是,在函数中我使用了几个std::string,假设在std::string 的初始化过程中出现了错误,并抛出 bad_allocout_of_range(或者 std::string 可能出错的任何其他问题)。

仍然添加 throw() 后缀是否仍然安全?

最佳答案

赫伯萨特 says那个

exception specifications confer a lot less benefit than they're worth

它带来的问题多于带来的好处。所以,在这样做之前你应该三思而后行。

关于c++ - 在包含 std::string 的函数上使用 throw() 后缀是否安全?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10261335/

相关文章:

Python ftplib STORE 可靠吗?

javascript - 强大的 Javascript 异常处理

spring - 如何通过 ControllerAdvice 在 ExceptionHandling 中设置优先级

Python:静态检测未处理的异常

c++ - C++中重载赋值运算符的返回类型

python - 如何退出 try block 并显示异常消息?

javascript - 在 node.js 中优雅地重启

c++ - 简单的c++输入程序

c++ - Qt 4 QAtomicInt : How to load() and store()?

c++ - 奇怪 - mysql 的 sql::SQLException 未被其类型捕获,而是被捕获为 std::exception 并成功投回