Menu

Wednesday 20 February 2013

New features in SQL Server 2012

Exception handling



In 2005 and 2008 versions, if you want to return the error first get error details using ERROR_MESSAGE ()  and then raise error.In 2012, it can be done by using THROW

Eg:

--2005/2008
BEGIN TRY
ERROR
END TRY
BEGIN CATCH
DECLARE @VSTR_ERROR_MSG VARCHAR (100);
SET @VSTR_ERROR_MSG=ERROR_MESSAGE ();
RAISERROR (@VSTR_ERROR_MSG, 15, 1);
END CATCH

--2012
BEGIN TRY
ERROR
END TRY
BEGIN CATCH
THROW
END CATCH

                                                  Go to Main Page               LAG() to fetch Previous Value >>

No comments:

Post a Comment