为什么我不能处理这个溢出异常而不能做最终范围? [英] why i cant handle this overflow exception and can not do finally scope ?

查看:75
本文介绍了为什么我不能处理这个溢出异常而不能做最终范围?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

static void Main(string[] args)
{
try
{
Console.WriteLine("This is In Try");

Program p = new Program();
p.ExecuteOverflow(new Program());
}
catch (SystemException sex)
{
Console.WriteLine("This is catch with system exception : {0}", sex.ToString());
}
catch (Exception ex)
{
Console.WriteLine("This is in Catch with exception: {0}", ex.ToString());
}
finally
{
Console.WriteLine("In finally");
}

}
public void ExecuteOverflow(Program p)
{
p.ExecuteOverflow(new Program());
}

推荐答案

好点。



一旦出现溢出异常,堆栈上就没有空间来执行 finally 块。 br />
因此,最后未执行。



还有一些其他最终不执行的场景。

其中一个是 ExecutingEngineException



事实上,有一些例外情况, finally 块的执行无法保证。



然而,溢出(以及其他这些)是错误,你的程序很可能无法恢复并将关闭。

因此,最终未执行。



这个msdn链接 [ ^ ]将为您提供更多洞察力。
Good point.

Once there is an overflow exception, there is no space on the stack to execute a finally block.
As a result, finally is not executed.

There are a few other scenarios where finally does not execute.
One of them is the ExecutingEngineException.

Infact, there are a few exceptions where execution of the finally block is not guaranteed.

However, overflow (and these other others) are errors where in all probability your program cannot recover and will shutdown.
As a result, it makes some sense that finally is not executed.

This msdn link[^] will give you little more insight.


这篇关于为什么我不能处理这个溢出异常而不能做最终范围?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆