From my experience, exception codes are mainly used as an informational message to the user.
I have not even seen that someone is trying to parse a general exception message in order to react differently, it depends on the error code, usually this is done through an exception hierarchy.
On the other hand, it would be difficult to create a new exception subclass for each specific case, and then use exception codes.
For example, if for the user code it does not take into account why the transaction failed, it should refuse it in any case, but for the end user it is important why this happened (incorrect parameters, connection to the database or other).
So, to summarize, if you expect different ways of handling different situations, it is better to use different types of exceptions, but if you should handle several problems the same way, but only notify the user about a specific reason, it is easier to use exception codes.
Ruslan Dzhabbarov
source share