DECLARE @retryCount INT
SET @retryCount = 3
Retry: BEGIN TRY
BEGIN TRAN
-- do work here
COMMIT TRAN
END TRY
BEGIN CATCH
DECLARE @error_message NVARCHAR(MAX)
SET @error_message = ERROR_MESSAGE()
DECLARE @error_severity INT
SET @error_severity = ERROR_SEVERITY();
DECLARE @error_state INT
SET @error_state = ERROR_STATE();
IF @error_state = 0 SET @error_state = 1
IF ERROR_NUMBER() = 1205 BEGIN
IF @retryCount > 0 
	SET @retryCount = @retryCount - 1
IF XACT_STATE() <> 0 ROLLBACK TRAN
GOTO Retry
END
-- do error processing here
RAISERROR (@error_message, 
	@error_severity, @error_state)
END CATCH
a
b
c
d
e
f
g
