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

前端 未结 4 1792
野的像风
野的像风 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:24

    You specified that UserExists and UsernameExists both make DB calls. I'll assume that CreateUser also makes a database call.

    Why not let the database handle your threading issues? Assuming further that there are proper constraints set up on your table(s), you can let it err-out within a stored proc call.

    Therefore, I'll cast my vote for Create-Catch.

提交回复
热议问题