是“死是真棒"吗?首选? [英] Is "Dying is Awesome" preferred?

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

问题描述

最近我参加了 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 recovery}"来包装顶级执行.实际上,如果从 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.

你怎么看?

推荐答案

我认为这取决于您正在运行的应用程序类型以及死亡"的后果是什么.对于许多客户端应用程序来说,死亡是一件很棒的事情.对于服务器来说,通常不是那么多(swallow-and-log 是合适的).没有一刀切的解决方案.

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.

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

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