Exception Handling Considered Harmful


Do, or do not. There is no try.

— Yoda, The Empire Strikes Back
(George Lucas)

Recent programming languages such as Java, Python and Ruby have chosen to use exception handling as their primary method of error handling, replacing the traditional approach of error return codes. I believe continuing this trend for future programming languages would be a mistake, for two reasons...

最近的编程语言如 Java, Python 和 Ruby 选择使用异常处理(exception handling)作为其主要的错误处理方法, 取代了传统的返回错误码方法. 我相信在未来的编程语言中继续这种趋势将是一个错误, 原因有两个...

Good Intentions


Exception handling was originally intended to solve several perceived problems with the traditional approach of error handling via return codes.



The original purpose of exception handling is to solve several perception problems of traditional error handling methods through return codes.

First, by separating the error handling code from the main body of normal code, it was hoped that the code would be less cluttered, and hence cleaner, with the normal, non-error case easier to follow because it was not obscured by necessary but tedious and unlikely error checking/handling.

首先, 通过将错误处理代码与正常业务代码分离, 希望代码不会那么混乱, 因此 更干净, 正常的, 非错误的情况更容易理解, 因此他没有必要的, 但繁琐的且不太常见的错误检查/处理.


扫描二维码关注本站微信公众号 Johngo学长
或者在微信里搜索 Johngo学长
回复 svip 获取验证码
wechat Johngo学长