[英]A class using another class's method c++
I have two classes, A
, and B
. 我有两个班级
A
和B
They are declared thusly: 因此,它们被声明为:
class A
{
public: void function() throw (exception);
};
class B
{
public: void function();
};
B::function
calls A::function
. B::function
调用A::function
。 Inside B::function
, I want to suppress the exception that A::function
sometimes throws, and continue execution afterwards. 在
B::function
内部,我想抑制A::function
有时抛出的异常,然后继续执行。 How do I do this? 我该怎么做呢?
You can drop all exceptions using try { .. } catch ( ... ) { }
: 您可以使用
try { .. } catch ( ... ) { }
删除所有异常:
void ClassB::doSomething()
{
try {
classAObject.doSomethingWhichMayThrow();
} catch ( ... ) {
}
}
Please note that this may have moral implications. 请注意,这可能会产生道德影响。 You should be ready to explain (at least in a comment of the code) why swallowing exceptions at this point is acceptable.
您应该准备好解释(至少在代码注释中)此时可以接受异常的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.