Which design is most preferable: test-create, try-create, create-catch?

前端 未结 4 1786
野的像风
野的像风 2021-01-30 16:20

Let\'s assume there is an operation that creates a user. This operation may fail if specified email or username exists. If it has failed, it is required to know exactly why. The

4条回答
  •  既然无缘
    2021-01-30 16:29

    Test-Create can cause race conditions, so it's not a great idea. It also likely does extra work.

    Try-Create is good if you expect errors to be part of normal code flow (such as in the case of user input).

    Create-Catch is good if errors are truly exceptional (so you're not worried about performance).

提交回复
热议问题