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
This is somewhat subjective, but there are some concrete pros and cons that are worth pointing out.
One drawback of the test-create approach is the race condition. If two clients attempt to create the same user at approximately the same time, it may be possible for them to both pass the tests, and then attempt to create same user.
Between Try-Create and Create-Catch, I prefer Create-Catch, but that's personal taste. One could argue that Create-Catch uses exceptions for flow control, which is usually frowned upon. On the other hand, Try-Create requires a somewhat awkward output
parameter, which could be more easily overlooked.
So, I prefer Create-Catch, but there's definitely room for debate here.