1

. Hi,

Good morning.

Would you please let me know whether we need to write exception handling mechanism (Try, Catch blocks) in database stored procedures? Is it the best Practice? (As the corresponding error will be thrown to the calling ASP.NET application itself whenever an error occurs in the database stored procedure.)

Thanks and Regards..

Shruthi Keerthi.

2 Answers 2

2

It really depends. In my opinion it is typically best to let your App (c#) catch and handle errors. I think the key use case for using try/catch inside of a stored proc is when you are expecting the possibility of a specific error condition and you have a T-SQL solution you want to invoke when that exception occurs.

Sign up to request clarification or add additional context in comments.

Comments

0

it depends on how you want to do it. however, you should be completely consistent throughout your application.

you can try to do everything within the Procedures and return nice context ready error messages and logging of local values and errors. however you will still need to do a final catch in ASP just to be sure

you could just do everything within ASP, but you won't have the nice local context messages and logging.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.