本文介绍了是“死是真棒"?首选?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我参加了 Jeffrey Richter 的 .NET 培训课程.他提到了一种编码策略死是真棒".也就是说,即使在程序或事件循环的根部也不要写catch (Exception ex)".如果抛出了一些未处理的异常,就让进程死掉.

Recently I attended Jeffrey Richter's training courses about .NET. He mentions one strategy of coding "Dying is awesome". That is, don't write "catch (Exception ex)" even at the root of program or event loop. If some exception thrown that is not handled, just let the process die.

我不确定这是否正确.就个人而言,我更喜欢在执行的顶层使用try {...} catch(Exception ex) {log and try to recover}"来包装.实际上,如果从 asXx 抛出任何异常,ASP.NET 不会死.如果它确实因异常而死,那么一个灵丹妙药的请求可以使整个服务保持沉默.

I'm not sure this is right. Personally, I prefer to have a "try {...} catch(Exception ex) {log and try to recover}" to wrap at the top level of execution. Actually, ASP.NET doesn't die if any exception is throw from asXx. If it does die for exception, then one silver-bullet request can silence the whole service.

你怎么看?

推荐答案

我认为这取决于您正在运行什么样的应用程序以及死亡"的后果是什么.对于许多客户端应用程序来说,死亡真是太棒了.对于服务器,通常不是那么多(吞下日志是合适的).没有万能的解决方案.

I think it depends on what kind of app you are running and what the consequences of 'dying' are. For many client apps, dying is awesome. For servers, often not so much (and swallow-and-log is appropriate). There's no one-size-fits-all solution.

这篇关于是“死是真棒"?首选?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 12:10