When is it appropriate to use error codes?

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

    I'm a newbie to stack overflow but...

    I believe that error codes tend to be used or useful for dealing with erroneous situations that require an end-user of sorts to get involved to rectify a situation. If your code is to be maintained by another developer then exceptions is the way to go. However, in a situation where there is a problem:

    • in the environment that your application is running

    • with communication between your app and some other entity (web server, database, socket, etc)

    • that a device or device driver indicates (hardware failure maybe?)

    then error codes may make sense. For example, if your app attempted to log into a database on behalf of your end-user, but the DB was unreachable for authentication (DB is off-line, cable is unplugged) then an error code/description combo might help the end-user rectify the problem.

    Again at the developer/engineer level who will be able to touch the source code (traditional debugging and testing techniques) and modify it, use exceptions.

    Hope this helps...

    --jqpdev

提交回复
热议问题