SQL Server 2012抛出Catch块

时间:2018-01-24 07:04:59

标签: sql-server sql-server-2012

BEGIN CATCH

      SELECT  ERROR_NUMBER() AS [Error Number],
      ERROR_MESSAGE() AS [ErrorMessage];  

      IF ERROR_NUMBER() IN (  1204, -- SqlOutOfLocks
                              1205, -- SqlDeadlockVictim
                              1222, -- SqlLockRequestTimeout
                              3960,  -- Snapshot Conflict
                              3930  --The current transaction cannot be committed and cannot support operations that write to the log file
                              )
      BEGIN
            SET @RetryCount = @RetryCount + 1  

            WAITFOR DELAY '00:00:05'  --let the blocking transaction finish
      END 
      ELSE    
      BEGIN
            -- If we don't have a handler for current error
            -- then we throw an exception and abort the loop
            THROW;
    END
END CATCH

我在我的程序中使用上面的代码,Throw语句在管理工作室中显示红线。我能够成功部署该过程。我们需要在抛出之前有一个声明,还是我们可以在抛出之前加上分号。

;投掷

0 个答案:

没有答案