这个声明是什么意思?exception()throw() [英] what does this declaration mean? exception() throw()

查看:52
本文介绍了这个声明是什么意思?exception()throw()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

std :: exception类的定义如下

std::exception class is defined as follows

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

throw()语法在声明中意味着什么?throw()可以接受参数吗?没有参数是什么意思?

what does the throw() syntax mean in a declaration? Can throw() take parameters? What does no parameters mean?

推荐答案

没有任何参数,表示所提到的函数不会不会抛出任何异常.

Without any parameter, it means that the mentioned functions does not throw any exceptions.

如果将任何内容指定为参数,则表示该函数将仅引发该类型的异常.但是请注意,这不是编译器的强制实施.如果碰巧抛出其他类型的异常,则程序将调用std :: terminate().

If you specify anything as a parameter, you're saying that the function will throw only exceptions of that type. Notice, however, this is not an enforcement to the compiler. If an exception of some other type happens to be thrown the program will call std::terminate().

这篇关于这个声明是什么意思?exception()throw()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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