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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 How to add error handling for stored procedures?
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

216 Posts

Posted - 02/14/2013 :  09:32:36  Show Profile  Reply with Quote
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?

Flowing Fount of Yak Knowledge

United Kingdom
3385 Posts

Posted - 02/14/2013 :  09:37:58  Show Profile  Visit nigelrivett's Homepage  Reply with Quote
see this

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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000