When is it appropriate to use error codes?

后端 未结 10 1740
日久生厌
日久生厌 2020-12-10 01:36

In languages that support exception objects (Java, C#), when is it appropriate to use error codes? Is the use of error codes ever appropriate in typical enterprise applicati

10条回答
  •  既然无缘
    2020-12-10 02:33

    Error codes are old-school. They are of little to no value at all.

    The only possible value to an error code is that it can identify a very specific circumstance. You could have a code for each point in the code base that can throw an exception. This would allow you to narrow down very precisely what the problem must be.

    But nobody cares about that level of detail. Who wants to maintain such a mess. It would leave you with codes that meant something like "condition A and B but not C due to state S". It's more effort than it's worth to try to work out exactly what that means. A stack trace will be more valuable in telling you where in the program the problem occurred.

    I learned to program computers before exceptions were a widespread technique. I'm so glad we got exceptions instead!

提交回复
热议问题