I am trying to return user friendly error message when a Mysql Exception is thrown in c#. I am currently returning the exception message but that message is not very user friendly. So I was wondering if any one of you had any trick that does not require any fancy regex parsing of the error messages received to display them to the user in a manner that would make sense to them.
I am trying to stay away from complex validation code prior to inserting/updating/deleting a record but that seems to be the only way … unless you know better!
As Marc B pointed that every Mysql error has an error code, so you can catch a
MySqlExceptionusing atry ... catchblock like this:So you can write a case statement to provide the error message for each error code, here are a list of server error codes and messages.