English 中文(简体)
源自下列各点的例外情况:C++11例外
原标题:Exception specifications when deriving from std::exception in C++11
  • 时间:2010-11-26 04:44:13
  •  标签:
  • c++
  • gcc
  • c++11

我有一个例外类别:

#include <exception>

struct InvalidPathException : public std::exception
{
   explicit InvalidPathException() {}
   const char* what() const;
};

const char*
InvalidPathException::what() const {
    return "Path is not valid";
}

根据海合会4.4与Wall-std=c++0x汇编

error: looser throw specifier for virtual const char* InvalidPathException::what() const

error: overriding virtual const char* std::exception::what() const throw ()

由于I m 优先于std: swhat(<>/code> 确实有throw( > 例外查询人。 但是,由于经常be informed ,我们就不使用例外光谱仪。 根据我的理解,它们是:,但显然尚未在海湾合作委员会得到――std=c++0x。

因此,我对目前的最佳办法感兴趣。 在代码I m发展中,我确实关心业绩,并对<代码>throw(<>>/代码>的上述间接费用感到担忧,但事实上,这种间接费用如此严重? 我正确地认为,我只是在以下时间才遭受痛苦:what(>)被实际称作,只有在这种例外被推翻之后才会这样做(同样,对于从中继承的其他方法,除外:所有的人都有<代码>>specifiers?

或者,是否有办法解决海合会提出的这一错误?

最佳回答

Empty throw specifications are useful, as they actually enable compiler optimizations at the caller s site, as Wikipedia knows (I don t have a technical quote handy).

由于优化机会,在即将出台的标准中做了解释,因此,没有说明具体内容: 而不是<>m> ,它们只是不像throw() 那样,而是称作no>。 确实,是,它们的工作略有不同。

Here, 讨论no extra,其中还详细说明了为什么传统的非排他性特异构体会在被点进行优化。

一般来说,你支付每张<条码>、的特约,至少要有一个完全符合规定的汇编者,在这方面,似乎并不总是这样做的。 这些<代码>throw规格必须在操作时间、甚至空闲时间加以核对。 这是因为,如果出现不符合<条码>第(4)/条码>规格的例外情况,就必须在这一条框内(因此,除了符合条令的检查外,还需要有这方面的代码)和随后的<条码>:必须打上“未具体说明<>。 另一方面,如果编辑在要求履行这一职能时可以作出更多的假设,则你可能节省每个网站的时间/空间<>。 我以言辞表示,只有一位简介员才能给你确切的答案,即您的具体法典是否受到或改进(<> >empt/>!”throws规格说明。

作为解决你实际问题的工作,可以开展以下工作?

  • Introduce #define NOTHROW throw () and use it for your exception s what and other stuff.
  • When GCC implements noexcept, redefine NOTHROW.

Update

如@ James McNellis notes,throw () will be forward-compatible. 在该案中,我刚刚建议使用<代码>throw(),除此以外,如果存在疑问,请作说明。

问题回答

暂无回答




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签