Say i have a stored proc that inserts some data into a table. If data is duplicate it will cause a sql server error (because i have unique index on some columns) and this error causes an exception in SqlClient. What can i do inside the stored proc to handle the error so no exception is being generated in my data access code?
Share
You can use
TRY CATCHwithin your stored procedures.This will allow you to do error handling withing SQL Server and not expose the errors to calling code.
Of course, if your
CATCHstatements cause exceptions/errors themselves they will be exposed to the client.However, you need to ask yourself if you really do not want to know such errors – they are indications of issues in your database/codebase.