Make Mysql Errors Caught in C #

I am trying to return a user friendly error message when a Mysql exception is thrown in C #. I am currently returning an exception message, but this message is not very convenient. So I was wondering if any of you have any trick that does not require any fancy analysis of the regular expressions of the received error messages in order to display them to the user in a way that would make sense to them.

I try to stay away from complex verification code before inserting / updating / deleting a record, but that seems the only way ... if you don't know better!

+5
source share
2 answers

Marc B , Mysql , MySqlException try ... catch :

try
{

}
catch (MySqlException ex)
{
    int errorcode = ex.Number;
}

, case , .

+6

sql

Try

Catch ex as SqlException
'''sql specific error message
''ie: 
response.write("oops! error message: " & ex.message)
Catch ex as Exception
'''any other runtime error messages
End Try
+1

All Articles