sqlserver2008 在函数中如何捕获异常

2024-12-17 03:13:47
推荐回答(2个)
回答1:

begin try
begin transaction
select 100/0 ---0 不能为除数
commit transaction
print 'transaction committed'
end try
begin catch
rollback
print 'transaction rolled back'
select ERROR_NUMBER() as ErrorNumeber,
ERROR_SEVERITY() as ErrorSeverity,
ERROR_STATE() as ErrorState,
ERROR_MESSAGE() as ErrorMessage;
end catch
go

回答2:

要捕获什么异常?用try catch