Monday, August 20, 2012

SQL Server: Generic Try/Catch Snippet

BEGIN TRY

-- do stuff

END TRY

BEGIN CATCH

                  DECLARE @PROC AS VARCHAR(100)
                  DECLARE @SERVER AS VARCHAR(200)
                  DECLARE @ERROR AS VARCHAR(4000)

                  SELECT @PROC = ERROR_PROCEDURE(),
                      @SERVER = @@SERVERNAME,
                      @ERROR = ERROR_MESSAGE();

END CATCH;

No comments:

Post a Comment