<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>TRY CATCH &#8211; Database Research &amp; Development</title>
	<atom:link href="https://www.dbrnd.com/tag/try-catch/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.dbrnd.com</link>
	<description>BIGData &#124; NoSQL &#124; MSSQL &#124; MySQL &#124; PostgreSQL</description>
	<lastBuildDate>Sun, 07 Jan 2018 20:11:31 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.0.6</generator>
	<item>
		<title>SQL Server: How to get a Stored Procedure name in CATCH Block</title>
		<link>https://www.dbrnd.com/2018/01/sql-server-how-to-get-a-stored-procedure-name-in-catch-block-error_procedure/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Tue, 23 Jan 2018 16:16:25 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[ERROR_PROCEDURE]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Error]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tuning]]></category>
		<category><![CDATA[SQL Server Programming]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[Stored Procedure Name]]></category>
		<category><![CDATA[TRY CATCH]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=4958</guid>

					<description><![CDATA[In this post, I am sharing a small and useful demonstration for printing a Stored Procedure name in the CATCH block of SQL Server. SQL Server developers are using TRY CATCH block in their Stored Procedures, but if they print Stored Procedure name in the CATCH block, it is easy to identify a particular stored [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-how-to-get-a-stored-procedure-name-in-catch-block-error_procedure%2F&amp;linkname=SQL%20Server%3A%20How%20to%20get%20a%20Stored%20Procedure%20name%20in%20CATCH%20Block" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-how-to-get-a-stored-procedure-name-in-catch-block-error_procedure%2F&amp;linkname=SQL%20Server%3A%20How%20to%20get%20a%20Stored%20Procedure%20name%20in%20CATCH%20Block" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-how-to-get-a-stored-procedure-name-in-catch-block-error_procedure%2F&amp;linkname=SQL%20Server%3A%20How%20to%20get%20a%20Stored%20Procedure%20name%20in%20CATCH%20Block" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-how-to-get-a-stored-procedure-name-in-catch-block-error_procedure%2F&amp;linkname=SQL%20Server%3A%20How%20to%20get%20a%20Stored%20Procedure%20name%20in%20CATCH%20Block" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-how-to-get-a-stored-procedure-name-in-catch-block-error_procedure%2F&amp;linkname=SQL%20Server%3A%20How%20to%20get%20a%20Stored%20Procedure%20name%20in%20CATCH%20Block" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-how-to-get-a-stored-procedure-name-in-catch-block-error_procedure%2F&amp;linkname=SQL%20Server%3A%20How%20to%20get%20a%20Stored%20Procedure%20name%20in%20CATCH%20Block" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2018%2F01%2Fsql-server-how-to-get-a-stored-procedure-name-in-catch-block-error_procedure%2F&#038;title=SQL%20Server%3A%20How%20to%20get%20a%20Stored%20Procedure%20name%20in%20CATCH%20Block" data-a2a-url="https://www.dbrnd.com/2018/01/sql-server-how-to-get-a-stored-procedure-name-in-catch-block-error_procedure/" data-a2a-title="SQL Server: How to get a Stored Procedure name in CATCH Block"></a></p><p>In this post, I am sharing a small and useful demonstration for printing a Stored Procedure name in the CATCH block of SQL Server. </p>
<blockquote><p>SQL Server developers are using TRY CATCH block in their Stored Procedures, but if they print Stored Procedure name in the CATCH block, it is easy to identify a particular stored procedure error from the error log files.</p></blockquote>
<p>It is also beneficial for an application developer to determine the name of the stored procedure with an error.<br />
We can use ERROR_PROCEDURE() to print a stored procedure name in the CATCH block. </p>
<p><strong>Below is a small demonstration on this:</strong></p>
<p><strong>Create a sample stored procedure:</strong></p>
<pre class="crayon-plain-tag">CREATE PROCEDURE usp_SampleErrorProc  
AS  
    PRINT 'Sample message...'
	SELECT 1/0;  
GO</pre> </p>
<p><strong>Execute above sample stored procedure:  </strong></p>
<pre class="crayon-plain-tag">BEGIN TRY  
    EXECUTE usp_SampleErrorProc  
END TRY  
BEGIN CATCH  
    SELECT 'Procedure_Name: ' + ERROR_PROCEDURE() AS ErrorProcedureName;  
END CATCH;  
GO</pre> </p>
]]></content:encoded>
					
		
		
			</item>
		<item>
		<title>SQL Server 2012: Introduced the new form of TRY CATCH Exception Handling using THROW</title>
		<link>https://www.dbrnd.com/2017/08/sql-server-2012-introduced-the-new-form-of-try-catch-exception-handling-using-throw/</link>
		
		<dc:creator><![CDATA[Anvesh Patel]]></dc:creator>
		<pubDate>Thu, 17 Aug 2017 16:16:54 +0000</pubDate>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Anvesh Patel]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[database research and development]]></category>
		<category><![CDATA[dbrnd]]></category>
		<category><![CDATA[SQL Query]]></category>
		<category><![CDATA[SQL Server 2012]]></category>
		<category><![CDATA[SQL Server Administrator]]></category>
		<category><![CDATA[SQL Server Error]]></category>
		<category><![CDATA[SQL Server Monitoring]]></category>
		<category><![CDATA[SQL Server Performance Tuning]]></category>
		<category><![CDATA[SQL Server Programming]]></category>
		<category><![CDATA[SQL Server Tips and Tricks]]></category>
		<category><![CDATA[throw]]></category>
		<category><![CDATA[TRY CATCH]]></category>
		<category><![CDATA[TSQL]]></category>
		<guid isPermaLink="false">https://www.dbrnd.com/?p=5881</guid>

					<description><![CDATA[As a DBA, I also defined the database coding standard in my organization in which I also created template for TRY &#8211; CATCH block. For few old projects, we are still working on SQL Server 2008, but after SQL Server 2012, I had to change the format of TRY &#8211; CATCH block. SQL Server 2012 [&#8230;]]]></description>
										<content:encoded><![CDATA[<p><a class="a2a_button_facebook" href="https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-2012-introduced-the-new-form-of-try-catch-exception-handling-using-throw%2F&amp;linkname=SQL%20Server%202012%3A%20Introduced%20the%20new%20form%20of%20TRY%20CATCH%20Exception%20Handling%20using%20THROW" title="Facebook" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_twitter" href="https://www.addtoany.com/add_to/twitter?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-2012-introduced-the-new-form-of-try-catch-exception-handling-using-throw%2F&amp;linkname=SQL%20Server%202012%3A%20Introduced%20the%20new%20form%20of%20TRY%20CATCH%20Exception%20Handling%20using%20THROW" title="Twitter" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_linkedin" href="https://www.addtoany.com/add_to/linkedin?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-2012-introduced-the-new-form-of-try-catch-exception-handling-using-throw%2F&amp;linkname=SQL%20Server%202012%3A%20Introduced%20the%20new%20form%20of%20TRY%20CATCH%20Exception%20Handling%20using%20THROW" title="LinkedIn" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pinterest" href="https://www.addtoany.com/add_to/pinterest?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-2012-introduced-the-new-form-of-try-catch-exception-handling-using-throw%2F&amp;linkname=SQL%20Server%202012%3A%20Introduced%20the%20new%20form%20of%20TRY%20CATCH%20Exception%20Handling%20using%20THROW" title="Pinterest" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_reddit" href="https://www.addtoany.com/add_to/reddit?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-2012-introduced-the-new-form-of-try-catch-exception-handling-using-throw%2F&amp;linkname=SQL%20Server%202012%3A%20Introduced%20the%20new%20form%20of%20TRY%20CATCH%20Exception%20Handling%20using%20THROW" title="Reddit" rel="nofollow noopener" target="_blank"></a><a class="a2a_button_pocket" href="https://www.addtoany.com/add_to/pocket?linkurl=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-2012-introduced-the-new-form-of-try-catch-exception-handling-using-throw%2F&amp;linkname=SQL%20Server%202012%3A%20Introduced%20the%20new%20form%20of%20TRY%20CATCH%20Exception%20Handling%20using%20THROW" title="Pocket" rel="nofollow noopener" target="_blank"></a><a class="a2a_dd addtoany_share_save addtoany_share" href="https://www.addtoany.com/share#url=https%3A%2F%2Fwww.dbrnd.com%2F2017%2F08%2Fsql-server-2012-introduced-the-new-form-of-try-catch-exception-handling-using-throw%2F&#038;title=SQL%20Server%202012%3A%20Introduced%20the%20new%20form%20of%20TRY%20CATCH%20Exception%20Handling%20using%20THROW" data-a2a-url="https://www.dbrnd.com/2017/08/sql-server-2012-introduced-the-new-form-of-try-catch-exception-handling-using-throw/" data-a2a-title="SQL Server 2012: Introduced the new form of TRY CATCH Exception Handling using THROW"></a></p><p>As a DBA, I also defined the database coding standard in my organization in which I also created template for TRY &#8211; CATCH block. </p>
<blockquote><p>For few old projects, we are still working on SQL Server 2008, but after SQL Server 2012, I had to change the format of TRY &#8211; CATCH block.<br />
SQL Server 2012 introduced the new form of CATCH block which I am using now for all new projects where we are using SQL Server 2014/2016.</p></blockquote>
<p>Below is a comparison between the New CATCH and Old CATCH:</p>
<p><strong>The old approach of CATCH:</strong></p>
<pre class="crayon-plain-tag">BEGIN TRY
	DECLARE @n AS INT;
	SET @n = 7/0
END TRY
BEGIN CATCH
	DECLARE @message NVARCHAR (4000)
	DECLARE @severity INT
	DECLARE @state INT

	SELECT @message = ERROR_MESSAGE ()
	SELECT @severity = ERROR_SEVERITY ()
	SELECT @state = ERROR_STATE ()

RAISERROR (@message,@severity,@state)
END CATCH</pre> </p>
<p><strong>Error message in result:</strong></p>
<pre class="crayon-plain-tag">Msg 50000, Level 16, State 1, Line 14
Divide by zero error encountered.</pre> </p>
<p><strong>The new approach of CATCH:</strong></p>
<pre class="crayon-plain-tag">BEGIN TRY
	DECLARE @n AS INT
	SET @n = 7/0
END TRY
BEGIN CATCH
	THROW
END CATCH</pre> </p>
<p><strong>Error message in result:</strong></p>
<pre class="crayon-plain-tag">Msg 8134, Level 16, State 1, Line 3
Divide by zero error encountered.</pre> </p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
