它是以往任何时候都好初步实践抛出一个异常finally块? [英] Is it ever good pratice to throw an exception in a finally block?

查看:116
本文介绍了它是以往任何时候都好初步实践抛出一个异常finally块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个很好的问题,抓当异常是从finallys 这是抛出讨论一些在finally块抛出异常的有时会出现意想不到的结果块不进行评估。

There's a good question Catch block is not being evaluated when exceptions are thrown from finallys that is discussing some of the sometimes unexpected results of throwing an exception in a finally block.

我可以'T认为任何好的理由,你为什么会想抛出一个异常,在finally块。如果有一个先前例外,它总是会丢失。我一直看到最后用来在不应该抛出异常的方式进行清理。

I can't think of any good reason why you would want to throw an exception in a finally block. If there was a previous exception, it would always be lost. I've always seen finally used to clean up in ways that should never throw an exception.

谁能解释何时是适当抛出一个异常在finally块?

Can anyone explain when it would be appropriate to throw an exception in a finally block?

推荐答案

这是好的,通过.NET很好的支持。问题是的的例外,这是一个非常贫穷的做法。你会正确地还原程序状态的几率是非常低的。

It is fine, well supported by .NET. The problem is catching the exception, that's a very poor practice. The odds that you'll properly restore program state are very low.

这篇关于它是以往任何时候都好初步实践抛出一个异常finally块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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