SQL Server – Error Handling Using TRY…CATCH

Prior to SQL server 2005, the only way of performing the error handling was to test vale of @@ERROR global variable. Once the SQL Server completes the execution of a Transact-SQL statement, it records the status of result in @@ERROR. If the error occurred, @@ERROR contains the error number. If the statement executed successfully it contain the 0. You need to check the variable if the statement succeeded or failed. Using @@ERROR to perform the error handling is not easy

» Read more