2018-04-30

Exception and Error

> to Japanese Pages

Exception and Error

1. Summary

One day, I was explaining the error architecture of a application in one project. However, before I explain the design, I had to explain “definition of Exception and Error” to project members. In this blog, I post an outline of the explanation at that time. FYI.

2. Introduction

Can you easily explain the difference between Exception and Error? Just the other day in a project, I received a question “I don't know the difference between Exception and Error.”. This question is very numerous. In the past, there were also programmers complaining about uninterrupted exception handling. In addition, there were some engineers that thought “Unexpected Error = Error” and “Expected Error = Exception.” Furthermore, there were some engineers that thought “Purpose Achieved = Exception” and “Purpose Un-achieved = Error.” The answer to this question “What is the difference between Exception and Error?” depends on which field you are talking about now. I will explain it now.

3. Exception and Error

First of all, you have to know that there is no concept that the difference between Exception and Error universally holds. There are many engineers who do not understand this. Therefore, a misunderstanding like the foreword occurs. In other words, it is impossible to clearly define the difference between an error and an exception as a universal concept. This is because the definition of "exception and error" differs depending on the field to be handled due to the historical background. Conversely, if it is not universal, its field-specific definition may exist. For example, Java is much clearer than other languages, but the difference with C++ is large. If you are discussing only specific field exceptions and error specifications, you should follow the specifications of that field. If not defined? The fact that it is not defined means that it is decided not to define or there is room for interpretation. About the above "pros and cons for non-interrupting exception handling", in Ruby, there is a retry mechanism in the exception mechanism. This means returning during exception processing. For example, in Python, the retry package is distributed. In Java and C++, the retry mechanism is not officially supported. However, I know the Java project that implements the retry mechanism on its own. Even in PHP, if you follow the constraints of the goto mechanism, return of exception handling can be implemented. Thus, the specification of "exception and error" in a particular language does not necessarily apply to other fields. In an undefined field, it is very nonsense that the concept of a specific field is enforced. If so, what should we think about in a wider range of system designs? It is good if you define it as necessary. The same is true for the error design of the application at the summary.

4. Conclusion

The difference between exceptions and errors, there is no universally established concept. The definition of exceptions and errors depends on the definition of each field. If it is defined, it suffices to follow its definition. If not defined it is best to interpret or define.