问题描述
考虑有一个类和一个全局函数:
Consider to have a class and a global function:
usefulfuncts.hpp
void dosome(int a, int b) throw (std::exception);
这是 usefulfuncts.cpp
void dosome(int a, int b) throw (std::exception) {
//...
}
这是aclass.hpp
And this is aclass.hpp
class aclass {
// Members...
friend void dosome(int a, int b) throw (std::exception);
// Members...
};
之后(我想要的)
好的!我想知道是否严格必须写每次 throw
子句。例如我可以这样做吗?
After (what I would like that to be)
Ok! I would like to understand if it is strictly necessary to write everytime the throw
clause. So for example can I do this?
这是 usefulfuncts.hpp
void dosome(int a, int b) throw (std::exception);
这是 usefulfuncts.cpp
void dosome(int a, int b) { /* OMITTING IT! */
//...
}
hpp
class aclass {
// Members...
friend void dosome(int a, int b); /* OMITTING IT */
// Members...
};
这是对的吗?只把它放在主声明中?感谢
Is this right? To put it only in the main declaration? Thanks
推荐答案
省略异常规范意味着您的函数可以引发 任何 exception。
Omitting a exception specification means that your function can throw any exception.
异常规格不良。几乎没有任何编译器正确实现该功能。自从C ++ 11标准以来,它们已被弃用。事实上,异常规范被认为是失败的实验,即使他们是C ++ 03标准的一部分。
Exceptions specifications are bad. There are hardly any compilers which implement the feature correctly. They have been deprecated since the C++11 Standard. In fact Exception specifications were considered a failed experiment even while they were a part of the C++03 standard.
良好阅读:
这篇关于C ++我需要写一个函数的throw子句吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!