<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; 2005 &#8211; Explanation of TRY&#8230;CATCH and ERROR Handling</title>
	<atom:link href="http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/</link>
	<description>Personal Notes of Pinal Dave</description>
	<lastBuildDate>Thu, 23 May 2013 14:22:59 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Karan Mistry</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-475749</link>
		<dc:creator><![CDATA[Karan Mistry]]></dc:creator>
		<pubDate>Wed, 15 May 2013 12:22:40 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-475749</guid>
		<description><![CDATA[Thanks... was simple in understanding]]></description>
		<content:encoded><![CDATA[<p>Thanks&#8230; was simple in understanding</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER &#8211; Weekly Series &#8211; Memory Lane &#8211; #024 &#124; SQL Server Journey with SQL Authority</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-454842</link>
		<dc:creator><![CDATA[SQL SERVER &#8211; Weekly Series &#8211; Memory Lane &#8211; #024 &#124; SQL Server Journey with SQL Authority]]></dc:creator>
		<pubDate>Sat, 13 Apr 2013 01:31:46 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-454842</guid>
		<description><![CDATA[[...] Explanation of TRY…CATCH and ERROR Handling SQL Server provides the TRY…CATCH construct, which is already present in many modern programming languages. TRY/CATCH helps to write logic separate the action and error handling code. The code meant for the action is enclosed in the TRY block and the code for error handling is enclosed in the CATCH block. In case the code within the TRY block fails, the control automatically jumps to the CATCH block, letting the transaction roll back and resume execution. In addition to this, the CATCH block captures and provides error information that shows you the ID, message text, state, severity and transaction state of an error. [...]]]></description>
		<content:encoded><![CDATA[<p>[...] Explanation of TRY…CATCH and ERROR Handling SQL Server provides the TRY…CATCH construct, which is already present in many modern programming languages. TRY/CATCH helps to write logic separate the action and error handling code. The code meant for the action is enclosed in the TRY block and the code for error handling is enclosed in the CATCH block. In case the code within the TRY block fails, the control automatically jumps to the CATCH block, letting the transaction roll back and resume execution. In addition to this, the CATCH block captures and provides error information that shows you the ID, message text, state, severity and transaction state of an error. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pavan</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-433413</link>
		<dc:creator><![CDATA[pavan]]></dc:creator>
		<pubDate>Thu, 07 Mar 2013 13:47:43 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-433413</guid>
		<description><![CDATA[Hi... Pinal

I have been following your blog and failed to understand why the stored procedure gets printed &quot;NULL&quot; when it goes to catch. It is returning the stored procedure name only when there is foreign key relationship violation. or else every time it is &quot;NULL&quot; Could you please help me .]]></description>
		<content:encoded><![CDATA[<p>Hi&#8230; Pinal</p>
<p>I have been following your blog and failed to understand why the stored procedure gets printed &#8220;NULL&#8221; when it goes to catch. It is returning the stored procedure name only when there is foreign key relationship violation. or else every time it is &#8220;NULL&#8221; Could you please help me .</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Richard Polunsky</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-330370</link>
		<dc:creator><![CDATA[Richard Polunsky]]></dc:creator>
		<pubDate>Tue, 14 Aug 2012 14:03:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-330370</guid>
		<description><![CDATA[that&#039;s a limitation of Sql Server 2005 - the first error is a compile time error, I think.]]></description>
		<content:encoded><![CDATA[<p>that&#8217;s a limitation of Sql Server 2005 &#8211; the first error is a compile time error, I think.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chirag Mehta</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-279683</link>
		<dc:creator><![CDATA[Chirag Mehta]]></dc:creator>
		<pubDate>Thu, 26 Apr 2012 05:00:16 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-279683</guid>
		<description><![CDATA[Hi..... Pinal

i m new to sql server, so i wanted to know that how can i return the error code using error_number() and error message using error_message() with variable to the calling............. like we can return in oracle using sqlcode, sqlerrm]]></description>
		<content:encoded><![CDATA[<p>Hi&#8230;.. Pinal</p>
<p>i m new to sql server, so i wanted to know that how can i return the error code using error_number() and error message using error_message() with variable to the calling&#8230;&#8230;&#8230;&#8230;. like we can return in oracle using sqlcode, sqlerrm</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER &#8211; T-SQL Errors and Reactions &#8211; Demo &#8211; SQL in Sixty Seconds #005 &#8211; Video &#171; SQL Server Journey with SQL Authority</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-260210</link>
		<dc:creator><![CDATA[SQL SERVER &#8211; T-SQL Errors and Reactions &#8211; Demo &#8211; SQL in Sixty Seconds #005 &#8211; Video &#171; SQL Server Journey with SQL Authority]]></dc:creator>
		<pubDate>Wed, 07 Mar 2012 01:30:42 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-260210</guid>
		<description><![CDATA[[...] on Errors: Explanation of TRY…CATCH and ERROR Handling Create New Log file without Server Restart Tips from the SQL Joes 2 Pros Development Series – SQL [...]]]></description>
		<content:encoded><![CDATA[<p>[...] on Errors: Explanation of TRY…CATCH and ERROR Handling Create New Log file without Server Restart Tips from the SQL Joes 2 Pros Development Series – SQL [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alek</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-258164</link>
		<dc:creator><![CDATA[Alek]]></dc:creator>
		<pubDate>Thu, 01 Mar 2012 08:49:12 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-258164</guid>
		<description><![CDATA[I&#039;ve got the same problem. Did you guys get answer to this question?]]></description>
		<content:encoded><![CDATA[<p>I&#8217;ve got the same problem. Did you guys get answer to this question?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Goutam</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-252735</link>
		<dc:creator><![CDATA[Goutam]]></dc:creator>
		<pubDate>Wed, 15 Feb 2012 07:00:36 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-252735</guid>
		<description><![CDATA[can we write insert statement in a trigger catch block in sql server 2005]]></description>
		<content:encoded><![CDATA[<p>can we write insert statement in a trigger catch block in sql server 2005</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER &#8211; T-SQL Errors and Reactions &#8211; SQL in Sixty Seconds #002 &#8211; Video &#171; SQL Server Journey with SQL Authority</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-252645</link>
		<dc:creator><![CDATA[SQL SERVER &#8211; T-SQL Errors and Reactions &#8211; SQL in Sixty Seconds #002 &#8211; Video &#171; SQL Server Journey with SQL Authority]]></dc:creator>
		<pubDate>Wed, 15 Feb 2012 01:31:19 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-252645</guid>
		<description><![CDATA[[...] on Errors: Explanation of TRY…CATCH and ERROR Handling Create New Log file without Server Restart Tips from the SQL Joes 2 Pros Development Series – SQL [...]]]></description>
		<content:encoded><![CDATA[<p>[...] on Errors: Explanation of TRY…CATCH and ERROR Handling Create New Log file without Server Restart Tips from the SQL Joes 2 Pros Development Series – SQL [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: MyDoggieJessie</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-197984</link>
		<dc:creator><![CDATA[MyDoggieJessie]]></dc:creator>
		<pubDate>Thu, 17 Nov 2011 21:37:15 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-197984</guid>
		<description><![CDATA[The best way to test for a linked server is to use SQL&#039;s built in system procedure:

Ex: EXEC sys.sp_testlinkedserver &#039;yourlinkedserver&#039;]]></description>
		<content:encoded><![CDATA[<p>The best way to test for a linked server is to use SQL&#8217;s built in system procedure:</p>
<p>Ex: EXEC sys.sp_testlinkedserver &#8216;yourlinkedserver&#8217;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sunil Somani</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-184990</link>
		<dc:creator><![CDATA[Sunil Somani]]></dc:creator>
		<pubDate>Sat, 29 Oct 2011 13:13:16 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-184990</guid>
		<description><![CDATA[which one we should use transaction/@@error or try/catch.]]></description>
		<content:encoded><![CDATA[<p>which one we should use transaction/@@error or try/catch.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: madhivanan</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-150054</link>
		<dc:creator><![CDATA[madhivanan]]></dc:creator>
		<pubDate>Fri, 22 Jul 2011 14:53:19 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-150054</guid>
		<description><![CDATA[Yes. But it is not possible without dynamic sql]]></description>
		<content:encoded><![CDATA[<p>Yes. But it is not possible without dynamic sql</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Prabbu</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-149712</link>
		<dc:creator><![CDATA[Prabbu]]></dc:creator>
		<pubDate>Thu, 21 Jul 2011 05:22:49 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-149712</guid>
		<description><![CDATA[ALTER PROC SAMPLE1
AS
BEGIN
	BEGIN TRY
		PRINT &#039;1&#039;
		DECLARE @SQL VARCHAR(MAX)
		SET @SQL = &#039;insert Permanenttable select * from Temporarytable&#039;
		EXEC(@SQL)
--		select 1/0
		PRINT &#039;2&#039;
	END TRY
	BEGIN CATCH
		print &#039;catch fired&#039;
		 SELECT 
        ERROR_NUMBER() AS ErrorNumber,
        ERROR_SEVERITY() AS ErrorSeverity,
        ERROR_STATE() as ErrorState,
        ERROR_PROCEDURE() as ErrorProcedure,
        ERROR_LINE() as ErrorLine,
        ERROR_MESSAGE() as ErrorMessage;   
	END CATCH
END]]></description>
		<content:encoded><![CDATA[<p>ALTER PROC SAMPLE1<br />
AS<br />
BEGIN<br />
	BEGIN TRY<br />
		PRINT &#8217;1&#8242;<br />
		DECLARE @SQL VARCHAR(MAX)<br />
		SET @SQL = &#8216;insert Permanenttable select * from Temporarytable&#8217;<br />
		EXEC(@SQL)<br />
&#8211;		select 1/0<br />
		PRINT &#8217;2&#8242;<br />
	END TRY<br />
	BEGIN CATCH<br />
		print &#8216;catch fired&#8217;<br />
		 SELECT<br />
        ERROR_NUMBER() AS ErrorNumber,<br />
        ERROR_SEVERITY() AS ErrorSeverity,<br />
        ERROR_STATE() as ErrorState,<br />
        ERROR_PROCEDURE() as ErrorProcedure,<br />
        ERROR_LINE() as ErrorLine,<br />
        ERROR_MESSAGE() as ErrorMessage;<br />
	END CATCH<br />
END</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shaik Nazeer Hussain</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-149711</link>
		<dc:creator><![CDATA[Shaik Nazeer Hussain]]></dc:creator>
		<pubDate>Thu, 21 Jul 2011 05:22:01 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-149711</guid>
		<description><![CDATA[I understand try catch blocks having some limitation.
But how can i handle this type of exception?
I am having scenario like following

Create procedure sp1
as 
Begin
     
     Begin Try
     Begin Tran
            
            Declare cursor1 cursor for ............
            ..................
            While @@Fetch_status=0
            Begin

                       Declare cursor2 cursor for ............
                       ..................
                       While @@Fetch_status=0
                       Begin

                                    Declare cursor3 cursor for ............
                                    ..................
                                    While @@Fetch_status=0
                                     Begin

                                                    insert Permanenttable
                                                    select * from Temporarytable
                                      End
                      End

               End

               IF @@TRANCOUNT &gt; 0     
	COMMIT TRAN
    End Try

    Begin catch

           Rollback tran
                  
          IF CURSOR_STATUS(&#039;GLOBAL&#039;, &#039;Cursor1&#039;) &gt;= 0 
              BEGIN 
                CLOSE Cursor1
                DEALLOCATE Cursor1
               END 
            IF CURSOR_STATUS(&#039;GLOBAL&#039;, &#039;Cursor2&#039;) &gt;= 0 
              BEGIN 
                CLOSE Cursor2
                DEALLOCATE Cursor2
               END 

            IF CURSOR_STATUS(&#039;GLOBAL&#039;, &#039;Cursor3&#039;) &gt;= 0 
              BEGIN 
                CLOSE Cursor3
                DEALLOCATE Cursor3
               END 
End catch

END


If exception raised at the time of inserting then it will terminate.But my all cursors will be open state only.

If next time i execute this SP it will give Cursor1 already exist and transaction opened error.

So can any one tell me how can i acheive this type of scenario.]]></description>
		<content:encoded><![CDATA[<p>I understand try catch blocks having some limitation.<br />
But how can i handle this type of exception?<br />
I am having scenario like following</p>
<p>Create procedure sp1<br />
as<br />
Begin</p>
<p>     Begin Try<br />
     Begin Tran</p>
<p>            Declare cursor1 cursor for &#8230;&#8230;&#8230;&#8230;<br />
            &#8230;&#8230;&#8230;&#8230;&#8230;&#8230;<br />
            While @@Fetch_status=0<br />
            Begin</p>
<p>                       Declare cursor2 cursor for &#8230;&#8230;&#8230;&#8230;<br />
                       &#8230;&#8230;&#8230;&#8230;&#8230;&#8230;<br />
                       While @@Fetch_status=0<br />
                       Begin</p>
<p>                                    Declare cursor3 cursor for &#8230;&#8230;&#8230;&#8230;<br />
                                    &#8230;&#8230;&#8230;&#8230;&#8230;&#8230;<br />
                                    While @@Fetch_status=0<br />
                                     Begin</p>
<p>                                                    insert Permanenttable<br />
                                                    select * from Temporarytable<br />
                                      End<br />
                      End</p>
<p>               End</p>
<p>               IF @@TRANCOUNT &gt; 0<br />
	COMMIT TRAN<br />
    End Try</p>
<p>    Begin catch</p>
<p>           Rollback tran</p>
<p>          IF CURSOR_STATUS(&#8216;GLOBAL&#8217;, &#8216;Cursor1&#8242;) &gt;= 0<br />
              BEGIN<br />
                CLOSE Cursor1<br />
                DEALLOCATE Cursor1<br />
               END<br />
            IF CURSOR_STATUS(&#8216;GLOBAL&#8217;, &#8216;Cursor2&#8242;) &gt;= 0<br />
              BEGIN<br />
                CLOSE Cursor2<br />
                DEALLOCATE Cursor2<br />
               END </p>
<p>            IF CURSOR_STATUS(&#8216;GLOBAL&#8217;, &#8216;Cursor3&#8242;) &gt;= 0<br />
              BEGIN<br />
                CLOSE Cursor3<br />
                DEALLOCATE Cursor3<br />
               END<br />
End catch</p>
<p>END</p>
<p>If exception raised at the time of inserting then it will terminate.But my all cursors will be open state only.</p>
<p>If next time i execute this SP it will give Cursor1 already exist and transaction opened error.</p>
<p>So can any one tell me how can i acheive this type of scenario.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: madhivanan</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-149601</link>
		<dc:creator><![CDATA[madhivanan]]></dc:creator>
		<pubDate>Wed, 20 Jul 2011 13:37:35 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-149601</guid>
		<description><![CDATA[The invalid object name error cannot be jhandled by CATCH block]]></description>
		<content:encoded><![CDATA[<p>The invalid object name error cannot be jhandled by CATCH block</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Shaik Nazeer Hussain</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-149575</link>
		<dc:creator><![CDATA[Shaik Nazeer Hussain]]></dc:creator>
		<pubDate>Wed, 20 Jul 2011 10:45:45 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-149575</guid>
		<description><![CDATA[Hi,

I am using sqlserver 2005.if i execute following lines of code in sqlserver catch bolck not executing.Since i dont have Permanenttable and Temporarytable in my db.

BEGIN TRY 
insert Permanenttable
select * from Temporarytable
END TRY 
BEGIN CATCH
print &#039;catch fired&#039;
END CATCH]]></description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>I am using sqlserver 2005.if i execute following lines of code in sqlserver catch bolck not executing.Since i dont have Permanenttable and Temporarytable in my db.</p>
<p>BEGIN TRY<br />
insert Permanenttable<br />
select * from Temporarytable<br />
END TRY<br />
BEGIN CATCH<br />
print &#8216;catch fired&#8217;<br />
END CATCH</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: obperryo</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-93052</link>
		<dc:creator><![CDATA[obperryo]]></dc:creator>
		<pubDate>Thu, 14 Oct 2010 14:29:54 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-93052</guid>
		<description><![CDATA[I understand the Try Catch, but how can I catch that the link server is down, and test it without taking down the link server?  

BEGIN TRY

	--SELECT 1/0
	SELECT state_desc FROM LinkedServerName.master.sys.databases WHERE [Name] = &#039;DBaseName&#039;

END TRY
BEGIN CATCH


SELECT
ERROR_NUMBER() AS ErrorNumber,
ERROR_SEVERITY() AS ErrorSeverity,
ERROR_STATE() AS ErrorState,
ERROR_PROCEDURE() AS ErrorProcedure,
ERROR_LINE() AS ErrorLine,
ERROR_MESSAGE() AS ErrorMessage;

END CATCH]]></description>
		<content:encoded><![CDATA[<p>I understand the Try Catch, but how can I catch that the link server is down, and test it without taking down the link server?  </p>
<p>BEGIN TRY</p>
<p>	&#8211;SELECT 1/0<br />
	SELECT state_desc FROM LinkedServerName.master.sys.databases WHERE [Name] = &#8216;DBaseName&#8217;</p>
<p>END TRY<br />
BEGIN CATCH</p>
<p>SELECT<br />
ERROR_NUMBER() AS ErrorNumber,<br />
ERROR_SEVERITY() AS ErrorSeverity,<br />
ERROR_STATE() AS ErrorState,<br />
ERROR_PROCEDURE() AS ErrorProcedure,<br />
ERROR_LINE() AS ErrorLine,<br />
ERROR_MESSAGE() AS ErrorMessage;</p>
<p>END CATCH</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sandipak Bagchi</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-89161</link>
		<dc:creator><![CDATA[Sandipak Bagchi]]></dc:creator>
		<pubDate>Thu, 23 Sep 2010 21:29:36 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-89161</guid>
		<description><![CDATA[Pinal,

Can you please provide some more info on NESTED TRY CATCH blocks and how the control passes from one to another during calling one stored procedure from another.

I have the following situation


CREATE PROCEDURE sp_a(
....)
AS
BEGIN...
..
BEGIN TRY   -- Outer Try block
   UPDATE TABLE a.....WHERE ...


EXEC sp_b

  UPDATE TABLE....
  SET a.....
  WHERE....

END TRY 
BEGIN CATCH

   SET @ErrorMsg = &#039;ErrNo: &#039; + ERROR_NUMBER() + &#039; Msg: &#039; +                    
                                ERROR_MESSAGE()

END CATCH

END

---- End of Stored Proc - sp_a

CREATE PROCEDURE sp_b(..
...)
...

BEGIN TRY  --- Nested Try Block - Inner block
     INSERT INTO TABLE.....
     VALUES(...)
END TRY
BEGIN CATCH

    SET @ErrorMsg = &#039;ErrNo: &#039; + ERROR_NUMBER() + &#039; Msg: &#039; +                    
                                ERROR_MESSAGE()
END CATCH

END  --- 

---- End of Stored Proc sp_b

So in this case if the sproc sp_b returns error, does the stored procedure capture that error and goes to the Outer CATCH block or do I have log the Inner CATCH error separately into a table.


Any feedback would be much appreciated]]></description>
		<content:encoded><![CDATA[<p>Pinal,</p>
<p>Can you please provide some more info on NESTED TRY CATCH blocks and how the control passes from one to another during calling one stored procedure from another.</p>
<p>I have the following situation</p>
<p>CREATE PROCEDURE sp_a(<br />
&#8230;.)<br />
AS<br />
BEGIN&#8230;<br />
..<br />
BEGIN TRY   &#8212; Outer Try block<br />
   UPDATE TABLE a&#8230;..WHERE &#8230;</p>
<p>EXEC sp_b</p>
<p>  UPDATE TABLE&#8230;.<br />
  SET a&#8230;..<br />
  WHERE&#8230;.</p>
<p>END TRY<br />
BEGIN CATCH</p>
<p>   SET @ErrorMsg = &#8216;ErrNo: &#8216; + ERROR_NUMBER() + &#8216; Msg: &#8216; +<br />
                                ERROR_MESSAGE()</p>
<p>END CATCH</p>
<p>END</p>
<p>&#8212;- End of Stored Proc &#8211; sp_a</p>
<p>CREATE PROCEDURE sp_b(..<br />
&#8230;)<br />
&#8230;</p>
<p>BEGIN TRY  &#8212; Nested Try Block &#8211; Inner block<br />
     INSERT INTO TABLE&#8230;..<br />
     VALUES(&#8230;)<br />
END TRY<br />
BEGIN CATCH</p>
<p>    SET @ErrorMsg = &#8216;ErrNo: &#8216; + ERROR_NUMBER() + &#8216; Msg: &#8216; +<br />
                                ERROR_MESSAGE()<br />
END CATCH</p>
<p>END  &#8212; </p>
<p>&#8212;- End of Stored Proc sp_b</p>
<p>So in this case if the sproc sp_b returns error, does the stored procedure capture that error and goes to the Outer CATCH block or do I have log the Inner CATCH error separately into a table.</p>
<p>Any feedback would be much appreciated</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Prashant Goyal</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-82308</link>
		<dc:creator><![CDATA[Prashant Goyal]]></dc:creator>
		<pubDate>Fri, 30 Jul 2010 06:26:12 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-82308</guid>
		<description><![CDATA[i want to know in sql script what type of
exception are generate like FOREGIN KEY,PRIMARY KEY, UNIQUE KEY VIOLATION 
so that i take a step to generate a appropriate message to
user that it understand what is error.]]></description>
		<content:encoded><![CDATA[<p>i want to know in sql script what type of<br />
exception are generate like FOREGIN KEY,PRIMARY KEY, UNIQUE KEY VIOLATION<br />
so that i take a step to generate a appropriate message to<br />
user that it understand what is error.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brad</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-81420</link>
		<dc:creator><![CDATA[Brad]]></dc:creator>
		<pubDate>Fri, 23 Jul 2010 15:18:50 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-81420</guid>
		<description><![CDATA[Ryan did you ever get an answer to your question.  I am having a similar issue.]]></description>
		<content:encoded><![CDATA[<p>Ryan did you ever get an answer to your question.  I am having a similar issue.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark Freeman</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-75104</link>
		<dc:creator><![CDATA[Mark Freeman]]></dc:creator>
		<pubDate>Mon, 07 Jun 2010 19:21:40 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-75104</guid>
		<description><![CDATA[I have a stored procedure that updates a linked server. The linked server is returning an error (because the update would violate a business rule). 

ERROR_MESSAGE() has &#039;Cannot fetch a row from OLE DB provider &quot;&quot; for linked server &quot;&quot;.&#039;

This is OK as far as it goes. But when I debug this in VS 2008, the Debug Window displays this much more detailed info:

OLE DB provider &quot;&quot; for linked server &quot;&quot; returned message &quot;Cursor fetch row failed.
exception 98
VER2021-Service Records can not overlap for DSP.&quot;.

How can I access that more detailed message within my stored procedure&#039;s CATCH block?]]></description>
		<content:encoded><![CDATA[<p>I have a stored procedure that updates a linked server. The linked server is returning an error (because the update would violate a business rule). </p>
<p>ERROR_MESSAGE() has &#8216;Cannot fetch a row from OLE DB provider &#8220;&#8221; for linked server &#8220;&#8221;.&#8217;</p>
<p>This is OK as far as it goes. But when I debug this in VS 2008, the Debug Window displays this much more detailed info:</p>
<p>OLE DB provider &#8220;&#8221; for linked server &#8220;&#8221; returned message &#8220;Cursor fetch row failed.<br />
exception 98<br />
VER2021-Service Records can not overlap for DSP.&#8221;.</p>
<p>How can I access that more detailed message within my stored procedure&#8217;s CATCH block?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ks</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-74874</link>
		<dc:creator><![CDATA[ks]]></dc:creator>
		<pubDate>Sat, 05 Jun 2010 14:07:36 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-74874</guid>
		<description><![CDATA[Is it possible for try..catch to be global for some reason? We are seeing stored procedures calling an error statement even though there is no error checking (try catch or otherwise) on that particular statement. For example, in the sp we might do inserts and on those we check @@error and we always do an insert into table called errors if we see a failure, but we have some update statements that we expect to not find anything to update in certain conditions so we do not check for any errors yet when they do not work we are getting an error on not being able to insert into the table errors and the sp bombs.  Is it possible for there to be a global try catch that gets called somehow?]]></description>
		<content:encoded><![CDATA[<p>Is it possible for try..catch to be global for some reason? We are seeing stored procedures calling an error statement even though there is no error checking (try catch or otherwise) on that particular statement. For example, in the sp we might do inserts and on those we check @@error and we always do an insert into table called errors if we see a failure, but we have some update statements that we expect to not find anything to update in certain conditions so we do not check for any errors yet when they do not work we are getting an error on not being able to insert into the table errors and the sp bombs.  Is it possible for there to be a global try catch that gets called somehow?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Geervani</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-66629</link>
		<dc:creator><![CDATA[Geervani]]></dc:creator>
		<pubDate>Sat, 24 Apr 2010 12:35:07 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-66629</guid>
		<description><![CDATA[Hello Sir,

Is there any way to catch error with severity less than 10.
I have a Stored Proc wherein dynamic sql query is generated. If the query is wrong, How can i catch the exception?

If the query generated can be wrong, than the user input is wrong and hence i need to update another table.

Can u pls help .. 

Thanks 
Geervani]]></description>
		<content:encoded><![CDATA[<p>Hello Sir,</p>
<p>Is there any way to catch error with severity less than 10.<br />
I have a Stored Proc wherein dynamic sql query is generated. If the query is wrong, How can i catch the exception?</p>
<p>If the query generated can be wrong, than the user input is wrong and hence i need to update another table.</p>
<p>Can u pls help .. </p>
<p>Thanks<br />
Geervani</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sandra</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-66165</link>
		<dc:creator><![CDATA[Sandra]]></dc:creator>
		<pubDate>Thu, 22 Apr 2010 08:56:47 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-66165</guid>
		<description><![CDATA[Hi , 

kindly let me know how to capture the exception raised by the below sql and i want to use insert Try and Catch in the sql below.

DECLARE @triprequest varchar (50)
DECLARE @xml_str varchar(4000)
DECLARE @hdoc int
declare  @temp_table_travel_Req_xml_det table ([triprequest] varchar (50),[name] varchar (50), [created_by] varchar (50), [action] varchar (16), [created_on] datetime)
DECLARE xml_cur cursor for
SELECT CMTRAVELCOMMENTS.tripRequest triprequest, cast(cast(CMTRAVELCOMMENTS.config as
varbinary(8000)) as VARCHAR(8000)) xml_str
FROM CMTRAVELCOMMENTS, PCMTRAVELREQUEST
WHERE
PCMTRAVELREQUEST.NODESTATE = &#039;Approved request&#039;
and CMTRAVELCOMMENTS.tripRequest=PCMTRAVELREQUEST.tripRequest
OPEN xml_cur
FETCH xml_cur into @triprequest,@xml_str
WHILE(@@fetch_status=0)
BEGIN
EXEC sp_xml_preparedocument @hdoc OUTPUT, @xml_str 
    INSERT into temp_table_travel_Req_xml_det
    SELECT @triprequest,*
    FROM OPENXML (@hdoc,&#039;/cm-comments/comments&#039;, 3)
        WITH ([name] varchar (50), [created_by] varchar (50), [action] varchar (16), [created_on] datetime) 
    EXEC sp_xml_removedocument @hdoc    
	print @triprequest 
FETCH xml_cur into @triprequest,@xml_str
END
CLOSE xml_cur
DEALLOCATE xml_cur]]></description>
		<content:encoded><![CDATA[<p>Hi , </p>
<p>kindly let me know how to capture the exception raised by the below sql and i want to use insert Try and Catch in the sql below.</p>
<p>DECLARE @triprequest varchar (50)<br />
DECLARE @xml_str varchar(4000)<br />
DECLARE @hdoc int<br />
declare  @temp_table_travel_Req_xml_det table ([triprequest] varchar (50),[name] varchar (50), [created_by] varchar (50), [action] varchar (16), [created_on] datetime)<br />
DECLARE xml_cur cursor for<br />
SELECT CMTRAVELCOMMENTS.tripRequest triprequest, cast(cast(CMTRAVELCOMMENTS.config as<br />
varbinary(8000)) as VARCHAR(8000)) xml_str<br />
FROM CMTRAVELCOMMENTS, PCMTRAVELREQUEST<br />
WHERE<br />
PCMTRAVELREQUEST.NODESTATE = &#8216;Approved request&#8217;<br />
and CMTRAVELCOMMENTS.tripRequest=PCMTRAVELREQUEST.tripRequest<br />
OPEN xml_cur<br />
FETCH xml_cur into @triprequest,@xml_str<br />
WHILE(@@fetch_status=0)<br />
BEGIN<br />
EXEC sp_xml_preparedocument @hdoc OUTPUT, @xml_str<br />
    INSERT into temp_table_travel_Req_xml_det<br />
    SELECT @triprequest,*<br />
    FROM OPENXML (@hdoc,&#8217;/cm-comments/comments&#8217;, 3)<br />
        WITH ([name] varchar (50), [created_by] varchar (50), [action] varchar (16), [created_on] datetime)<br />
    EXEC sp_xml_removedocument @hdoc<br />
	print @triprequest<br />
FETCH xml_cur into @triprequest,@xml_str<br />
END<br />
CLOSE xml_cur<br />
DEALLOCATE xml_cur</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Murugan Killada</title>
		<link>http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-65997</link>
		<dc:creator><![CDATA[Murugan Killada]]></dc:creator>
		<pubDate>Wed, 21 Apr 2010 18:36:01 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/04/11/sql-server-2005-explanation-of-trycatch-and-error-handling/#comment-65997</guid>
		<description><![CDATA[Check upfront if object exists or not.

If exists(
Select * from information_schema.tables where table_name=
)  ... then go ahead inserting data.]]></description>
		<content:encoded><![CDATA[<p>Check upfront if object exists or not.</p>
<p>If exists(<br />
Select * from information_schema.tables where table_name=<br />
)  &#8230; then go ahead inserting data.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
