McKelt.com

Remembering Thoughts

Recent comments

Authors

Categories


Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010

SQL Server error handling

CREATE PROCEDURE <procName>
/*^
* Procedure:     usp_TryCatchSkeleton
^*/
AS

BEGIN

   SET NOCOUNT ON

   BEGIN TRY

      --Do work

   END TRY

   BEGIN CATCH
/* Note that catching and rethrowing an exception is a lossy operation. ERROR_PROCEDURE() etc will be reset. */
      DECLARE @errorMessage   NVARCHAR(4000);
      DECLARE @errorSeverity  INT;
      DECLARE @errorState     INT;

      SELECT  @errorMessage   = ERROR_MESSAGE(),
              @errorSeverity  = ERROR_SEVERITY() ,
              @errorState     = ERROR_STATE();

      --Perform required recovery actions.

      RAISERROR ( @errorMessage, @errorSeverity, @errorState );
      
      RETURN 1;

   END CATCH
   
   RETURN 0;
END

Posted by chris on Friday, September 11, 2009 12:57 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Resharper Live Templates

image

Click here to download Resharper Templates


Posted by Chris on Friday, September 04, 2009 1:18 PM
Permalink | Comments (0) | Post RSSRSS comment feed