异常处理Windows服务中的最佳做法? [英] Exception handling best practice in a windows service?
问题描述
我已阅读 Scott Hanselman的文章的异常处理最佳实践,他写道,只有少数情况下你应该吞下一个例外。我认为Windows服务是少数几种情况之一,但我很乐意得到一些确认。
吞咽一个例外与放弃特定任务而不停止整个过程不同。
在我们的Windows服务中,我们捕获异常,记录其详细信息,然后优雅降级该任务并等待下一个任务。然后,我们可以在服务器仍在运行时使用该日志排除错误。
I am currently writing a windows service that runs entirely in the background and does something every day. My idea is that the service should be very stable so if something goes wrong it should not stop but try it next day again and of course log the exception. Can you suggest me any best practice how to make truly stable windows services?
I have read the article of Scott Hanselman of exception handling best practice where he writes that there are only few cases when you should swallow an exception. I think somehow that windows service is one of the few cases, but I would be happy to get some confirmation on that.
'Swallowing' an exception is different to 'abandoning a specific task without stopping the entire process'. In our windows service, we catch exceptions, log their details, then gracefully degrade that task and wait for the next task. We can then use the log to troubleshoot the error while the server is still running.
这篇关于异常处理Windows服务中的最佳做法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!