如何捕获初始化列表中的异常? [英] How to catch the exception in initialization list?
本文介绍了如何捕获初始化列表中的异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个关于如何在初始化列表中捕获异常的问题。
I have a question about how to catch the exception in the initialization list.
例如,我们有一个来自Bar
For example, we have a class Foo derived from Bar
class Foo {
public:
Foo(int i) {throw 0; }
}
class Bar : public Foo{
public:
Bar() : Foo(1) {}
}
推荐答案
我认为语法是像这(即使最好在调用者中捕获这样的东西,你要去什么)
I think the syntax is like this (even though it's better to catch such things in the caller. And what are you going to do once you caught it?)
Bar::Bar()
try
: Foo(1)
{
}
catch( const SomeException &e )
{
}
这篇关于如何捕获初始化列表中的异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文