throw()在c ++异常结构中的函数声明之后? [英] throw () after function declaration in c++ exception struct?

查看:310
本文介绍了throw()在c ++异常结构中的函数声明之后?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是 http://www.tutorialspoint.com/cplusplus/cpp_exceptions_handling.htm

#include <iostream>
#include <exception>
using namespace std;

struct MyException : public exception
{
  const char * what () const throw ()
  {
    return "C++ Exception";
  }
};



我理解 const $ c> what 意味着该函数不会修改struct的任何
成员,但结尾处的 throw()

I understand the const after what means the function does not modify any members of the struct, but what does the throw() at the end mean?

推荐答案

这意味着它不会抛出任何异常。这是一个重要的保证,例如 what ,通常在异常处理中调用:你不想要另一个异常抛出,而你试图处理一个。

It means it won't throw any exceptions. This is an important guarantee for a function like what, which is usually called in exception handling: you don't want another exception to be thrown while you're trying to handle one.

在C ++ 11中,通常应该使用 noexcept 。旧的投放规格已弃用。

In C++11, you generally should use noexcept instead. The old throw specification is deprecated.

这篇关于throw()在c ++异常结构中的函数声明之后?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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