为什么C ++使用throw()关键字指示函数不会抛出任何异常 [英] Why c++ use throw() keyword to indicate the function won't throw any exceptions

查看:79
本文介绍了为什么C ++使用throw()关键字指示函数不会抛出任何异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

此关键字是否有点违反直觉?

Is this keyword a bit of counter-intuitive ?

该函数不会引发任何异常,因此我们向其添加了throw()标记.应该是silent()还是类似的东西?

The function won't throw any exceptions so we add a throw() tag to it. Should it be silent() or something like that?

推荐答案

从C ++ 17以前的角度来看:它可能是违反直觉的,但只是一会儿. throw(type,type,...)提供该函数可能抛出的异常类型的列表. throw()提供了一个 empty 类型列表,即该函数不能抛出任何类型的异常.

From a pre-C++17 perspective: it may be counter-intuitive, but only for a moment. throw(type, type, ...) provides a list of types of exceptions that the function may throw. throw() is supplying an empty list of types, i.e. the function cannot throw any type of exception.

这篇关于为什么C ++使用throw()关键字指示函数不会抛出任何异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆