Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有两个班级A, 和B。它们是这样声明的:
A
B
class A { public: void function() throw (exception); }; class B { public: void function(); };
B::function来电A::function。在里面B::function,我想抑制A::function有时抛出的异常,然后继续执行。我该怎么做呢?
B::function
A::function
您可以使用以下方法删除所有异常try { .. } catch ( ... ) { }:
try { .. } catch ( ... ) { }
void ClassB::doSomething() { try { classAObject.doSomethingWhichMayThrow(); } catch ( ... ) { } }
请注意,这可能具有道德含义。您应该准备好解释(至少在代码的注释中)为什么此时吞下异常是可以接受的。