我想停止执行使用“try catch”时出现的任何错误,为什么有些错误会停止执行而其他错误不执行示例
示例1:
select 5;
exec( 'select * from tttt') ; -- tttt is not table
select 6
我可以安排结果
5 and 6 and Error Msg Msg 208, Level 16, State 1, Line 1 Invalid object name 'tttt'
在这种情况下我想跳过
示例2:
select 5;
update t1 set ID=1 ;--ID is Primary Key
select 6
结果只有错误消息
Msg 8102, Level 16, State 1, Line 3,Cannot update identity column 'ID'.
我知道Example2错误是在编译时和Sample1错误是在执行时间,但这只是我想要的例子。 对于示例1我希望结果为5,错误消息Msg 208而不继续执行返回6,所有不使用try catch或raiseerror或comapring @@ ERROR = 0