如果finally块抛出一个异常,会发生什么? [英] What happens if a finally block throws an exception?

查看:396
本文介绍了如果finally块抛出一个异常,会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果finally块抛出异常是什么究竟会发生什么?

特别是如果execption通过中途抛出finally块会发生什么。不要在此块语句的其余部分被调用?

我知道,异常将向上传播完成。


解决方案

  

如果finally块抛出异常是什么究竟会发生什么?


这异常传播出来了,会(能),在更高层次上进行处理。

您finally块将不会完成超越的地方抛出异常的地步。

如果finally块被处理前面的异常的话,首先异常丢失期间执行。


  

C#4语言规范和教派; 8.9.5:如果finally块抛出另一个异常,当前异常的处理终止。


If a finally block throws an exception what exactly happens?

Specifically what happens if the execption is thrown midway through a finally block. Do the rest of statements in this block get invoked?

I am aware that exceptions will propogate upwards.

解决方案

If a finally block throws an exception what exactly happens ?

That exception propagates out and up, and will (can) be handled at a higher level.

Your finally block will not be completed beyond the point where the exception is thrown.

If the finally block was executing during the handling of an earlier exception then that first exception is lost.

C# 4 Language Specification § 8.9.5: If the finally block throws another exception, processing of the current exception is terminated.

这篇关于如果finally块抛出一个异常,会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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