我在存储过程中有以下循环:
WHILE (@progress <= @total) BEGIN
IF (EXISTS(SELECT * FROM test WHERE to_cancel = 1 AND id = @Id)) BEGIN
UPDATE test SET status = 2 WHERE id = @Id;
WAITFOR DELAY '00:00:05';
BREAK;
END
WAITFOR DELAY '00:00:01';
BEGIN TRY
IF (@progress >= 10) BEGIN
;THROW 50001, 'Error raised', 1
END
SET @progress = @progress + 1;
UPDATE test
SET progress = @progress
WHERE id = @Id;
END TRY
BEGIN CATCH
UPDATE test SET status = -1 WHERE id = @Id;
WAITFOR DELAY '00:00:05';
BREAK;
END CATCH
END;
抛出错误并且循环中断。但是,UPDATE
中的CATCH
未被执行。
有原因吗?