sql | SQL Server‎ > ‎sqlsrv | T-SQL‎ > ‎

tsql | catch

IF @@TRANCOUNT > 0
ROLLBACK TRANSACTION;

DECLARE @ErrorNumber INT, @ErrorSeverity INT, @ErrorState INT, @ErrorProcedure nvarchar(126), @ErrorLine INT, @ErrorMessage nvarchar(4000)  

SELECT 
@ErrorNumber = ERROR_NUMBER(),  
@ErrorSeverity = ERROR_SEVERITY(),  
@ErrorState = ERROR_STATE(),    
@ErrorLine = ERROR_LINE(),  
@ErrorMessage = ERROR_MESSAGE();  

SET @ErrorMessage = 'Error in script at line '+ LTRIM(@ErrorLine)+':'+ @ErrorMessage   

RAISERROR (@ErrorMessage, @ErrorSeverity, 1) 
Comments