When is it appropriate to use error codes?

后端 未结 10 1758
日久生厌
日久生厌 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:25

    WITHIN a program one should always use exceptions instead of error codes. However, exceptions can't propagate beyond a program. Any time the error must leave the program you are left with error messages or error codes.

    For simple things that will always be human-operated error messages without codes are fine. You can say "File not found" without giving it an error code. However, if it might be another computer on the other end then you should give error codes in addition. You don't want to break the other system when you change it to "File not found".

提交回复
热议问题