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

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

问题描述

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

If a finally block throws an exception, what exactly happens?

具体来说,如果在 finally 块中途抛出异常会发生什么.此块中的其余语句(之后)是否被调用?

Specifically, what happens if the exception is thrown midway through a finally block. Do the rest of statements (after) in this block get invoked?

我知道异常会向上传播.

I am aware that exceptions will propagate upwards.

推荐答案

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

该异常会向外传播并向上传播,并将(可以)在更高级别进行处理.

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

您的 finally 块将不会在抛出异常的点之后完成.

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

如果在处理较早的异常期间执行 finally 块,则第一个异常将丢失.

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

C# 4 语言规范 §8.9.5:如果finally块抛出另一个异常,则终止当前异常的处理.

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天全站免登陆