Error handling in T-SQL can be complex.
TRY…CATCH certainly is the best way to handle errors in T-SQL.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
BEGIN TRY BEGIN TRANSACTION ------ ------ ------ COMMIT TRANSACTION; END TRY BEGIN CATCH ------ ------ ------ SELECT ERROR_NUMBER() AS ErrorNumber ,ERROR_SEVERITY() AS ErrorSeverity ,ERROR_STATE() AS ErrorState ,ERROR_PROCEDURE() AS ErrorProcedure ,ERROR_LINE() AS ErrorLine ,ERROR_MESSAGE() AS ErrorMessage; ROLLBACK TRANSACTION; END CATCH |
Leave a Comment