设计模式:异常/错误处理 [英] Design patterns: exception / error handling
问题描述
有很多关于如何编写干净代码的文献,有很多书籍涵盖了设计模式。然而,我从来没有看到任何设计模式,涵盖了哪里和如何最好地处理错误,以及如何最好地传播出现在低级别功能中的错误,提升抽象层次。
这些模式和最佳做法经常被绑定到一个特定的平台/语言,所以他们是第一个寻找他们的地方。
- 异常模式wiki 是一般的模式资源。
作为一个例子,检查以下Java的链接:
通过这些材料可以提供一般的想法来遵循异常处理机制。
还要检查其他SO问题:
Is there any resource (web or book) describing exception handling / error handling design patterns?
There is a lot of literature on how to write clean code, and there are a lot of books covering design patterns. I have, however, never seen any design pattern covering the issue of where and how best to handle errors and how best to propagate an error appearing in a low-level function up the levels of abstraction.
These patterns and best practices are often bound to a specific platform/language, so they are the first place to look for them.
- Exception patterns wiki is a general patterns resource.
As an example check the following links for java:
- Best Practices for Exception Handling
- 15 Best practices about exception handling
- Exception-Handling Antipatterns
Going through such materials would give you a general idea to follow in exception handling mechanisms.
Also check other SO questions:
这篇关于设计模式:异常/错误处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!