Q

Problems with structured exception handling

I recently read your article "Tuning stored procedures: Structured exception handling in SQL Server 2005" and I was trying to implement the concept discussed. It seems the control doesn't enter into the catch block. What should I do?

I recently read your article " Tuning stored procedures: Structured exception handling in SQL Server 2005" and I was trying to implement the concept discussed. However, it seems the control doesn't enter into the catch block. What should I do?
Try a much simpler example first. This example will fail because we attempt to insert a NULL value into a column that does not allow NULLs:

CREATE TABLE dbo.emp ( empno int NOT NULL) go create procedure  dbo.p_emp_insert (@empno int) as begin  -- CODE THAT MAY FAIL   begin try   insert into emp (empno)             values (@empno)       end try  -- EXECUTED IF THERE IS A FAILURE  begin catch     SELECT ERROR_NUMBER()as ERROR_NUMBER,     ERROR_SEVERITY()as ERROR_SEVERITY,     ERROR_STATE()as ERROR_STATE,     ERROR_MESSAGE()as ERROR_MESSAGE  end catch end -- First exec should...

work with a valid empno … exec dbo.p_emp_insert 1003 -- This should fail because the column does not allow NULLs -- We should see the error information returned exec p_emp_insert NULL

This was first published in October 2006

Dig deeper on SQL Server Stored Procedures

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchBusinessAnalytics

SearchDataCenter

SearchDataManagement

SearchAWS

SearchOracle

SearchContentManagement

SearchWindowsServer

Close