From the UI designer standpoint you shouldn’t allow the user to perform actions that will cause errors. This is an example when you know that might happen and can prevent it.
For example, if a user is choosing both values from dropdown lists you should filter their contents in such way that choosing an existing pair is impossible.
A little off topic:
The same goes for action buttons, if it can’t be performed don’t let user click the button and then display an error message, just make that button disabled, optionally with a note next to it or in a popover why it is so.