Say, you pre-validate if a username already exist in a registration form in the application layer. E.g., You send back a nice "username already exist" error message to the user.
While unlikely, there's still a possibility that two different users can "simultaneously" pass the application layer validator and one of them will eventually get a "duplicate entry" exception from the database layer.
In this scenario, is it good practice to still catch the database layer exception and send back a nice error message to the user. Or, is that overkill, and you just let it "slide" and halt the application with a 500 error?
Note: letting it slide may also trigger your 500 error alerts, if any, at 3AM for what is actually just a "minor" validation error :-)
I know this is an unlikely scenario but still can happen, what's your approach on it?