views:

143

answers:

2

. 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.

+1  A: 

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.

Matt Wrock
A: 

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.

KM