关于例外的简单问题 [英] simple question on exceptions
本文介绍了关于例外的简单问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
想象一下,我有以下代码:
尝试
{
f();
}
catch (...)
{
}
这是f()的定义
viod f()
{
// 调用其他函数f1
f1();
}
这是f1:
void f1()
{
throw 100 ; // 我很好奇这个扔会被上面的catch块捕获吗?
}
谢谢。
解决方案
当抛出异常时代码将继续向上堆栈跟踪,直到找到一个捕获。所以,是的,它会被捕获。
当然,这是一个简单的例子,你可以自己测试一下。 :)
Hi,
Imagine I have following code:
try
{
f();
}
catch(...)
{
}
This is definition of f()
viod f()
{
// call other function f1
f1();
}
This is f1:
void f1()
{
throw 100; // I am curious will this "throw" be caught by the catch block above?
}
Thanks.
解决方案
When an exception is thrown the code will continue up the stack trace until it finds a catch. So, yes, it will be caught.
Of course, this is simple example and you could test it yourself. :)
这篇关于关于例外的简单问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文