When is it appropriate to use error codes?

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

    Very common for web service interfaces. It's very easy and standard to return a code with a description.

    I agree that for most of the scenarios is old school

    I'd say the biggest disadvantages it's the quality of code. You have to add more complex logic to manage error codes while exceptions are bubbled without having to use method parameters or return values.

    You also have to add an "IF" to check if the returned code is SUCCESS or not, while exceptions goes directly to the error handling block.

提交回复
热议问题