Is quot;Dying is Awesomequot; preferred?(是“死是真棒?首选?)
问题描述
最近我参加了 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.
这篇关于是“死是真棒"?首选?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:是“死是真棒"?首选?
基础教程推荐
- c# Math.Sqrt 实现 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01