错误处理理论? [英] Theory on error handling?

查看:109
本文介绍了错误处理理论?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有关错误处理的大多数建议都归结为一些提示和技巧(参见此帖)。这些提示是有帮助的,但我认为他们不回答所有问题。我觉得我应该根据一定的哲学来设计我的应用程序,一个思想提供了坚实的基础。是否有这样一个关于错误处理主题的理论?

Most advice concerning error handling boils down to a handful of tips and tricks (see this post for example). These hints are helpful but I think they don't answer all questions. I feel that I should design my application according to a certain philosophy, a school of thought that provides a strong foundation to build upon. Is there such a theory on the topic of error handling?

这里有一些实际问题:


  • 如何确定错误是否应在本地处理或传播到更高级别的代码?

  • 如何决定记录错误或将其显示为错误消息

  • 是否记录了应该仅在应用程序代码中执行的操作?

  • 如果出现异常,应该如何捕捉它们?在低级别或更高级别的代码中?

  • 如果您通过所有代码层努力实现统一的错误处理策略,或者尝试开发一个可以适应各种错误的系统处理策略(以便能够处理来自第三方库的错误)。

  • 创建错误代码列表是否有意义?
  • How to decide if an error should be handled locally or propagated to higher level code?
  • How to decide between logging an error, or showing it as an error message to the user?
  • Is logging something that should only be done in application code? Or is it ok to do some logging from library code.
  • In case of exceptions, where should you generally catch them? In low-level or higher level code?
  • Should you strive for a unified error handling strategy through all layers of code, or try to develop a system that can adapt itself to a variety of error handling strategies (in order to be able to deal with errors from 3rd party libraries).
  • Does it make sense to create a list of error codes? Or is that old fashioned these days?

在许多情况下,常识足以开发一个足够好的策略来处理错误条件。但是,我想知道是否有更正式/学术的方法?

In many cases common sense is sufficient for developing a good-enough strategy to deal with error conditions. However, I would like to know if there is a more formal/"scholarly" approach?

PS:这是一个一般的问题, C ++是我工作的主要编程语言。)

PS: this is a general question, but C++ specific answers are welcome too (C++ is my main programming language for work).

推荐答案

几年前我想到了同样的问题:)

A couple of years ago I thought exactly about the same question :)

在搜索和阅读几个东西后,我认为最有趣的参考文献是用于生成,处理和错误管理的模式从Andy Longshaw和Eoin Woods。

After searching and reading several things, I think that the most interesting reference I found was Patterns for Generation, Handling and Management of Errors from Andy Longshaw and Eoin Woods. It is a short and systematic attempt to cover the basic idioms you mention and some others.

这些问题的答案是颇有争议的,但上面的作者勇敢地在会议中露出自己,然后把他们的想法放在纸上。

The answer to these questions is quite controversial, but the authors above were brave enough to expose themselves in a conference, and then put their thoughts on paper.

这篇关于错误处理理论?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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