SQL Try Catch
What is TRY… CATCH? The TRY... Catch construct was designed to improve the functionality in processing errors. With it comes a cleaner and more readable syntax that is familiar to programmers. In addition, this construct can return the transaction state of your procedures, and allow the developer to either log the details of the error, or return this information to the calling procedure. The new functions available with TRY... CATCH include XACT_STATE, ERROR_LINE, ERROR_MESSAGE, ERROR_NUMBER, ERROR_PROCEDURE, ERROR_SEVERITY, and ERROR_STATE. @@ERROR vs. TRY... CATCH Error handling in SQL Server 2000 and earlier consisted of the @@ERROR function. SQL Server 2005 introduced the TRY... Catch construct. These two error handling styles have varying ways of dealing with the errors produced. • @@ERROR is cleared and reset on each statement executed. This requires developers to test the error, or save it to a variable, after each TSQL statement. This greatly increases the lines of co...