Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to add error handling for stored procedures?

Author  Topic 

pras2007
Posting Yak Master

216 Posts

Posted - 2013-02-14 : 09:32:36
Hello All,

I have been given several stored procedures in SQL Server 2005; the goal is to modify the SP to raise an error for any error(s) that may occur. Does anyone know how to accomplish this task?

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2013-02-14 : 09:37:58
see this
http://www.nigelrivett.net/Products/DWBuilder/TraceTable.html

Just add a try - catch block to trap erors.
This then logs the error and re-raises it.
This will again be trapped and logged by a calling sp.
The good thing is that as long as the handling is in a higher level sp then all calling sps will have their errors trapped - I prefer to add it to all sps though so you get the stack.


==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -