Using TRY…CATCH to Handle SQL Server Errors
Tuesday June 24, 2008
The TRY…CATCH statement in Transact-SQL allows you to detect and handle error conditions gracefully within your database applications. This statement is the cornerstone of SQL Server error handling and is an extremely important part of developing robust database applications.
TRY..CATCH works by allowing you to specify two Transact-SQL statements: one that you wish to "try" and another that you wish to use to "catch" any errors that might arise. When SQL Server encounters a TRY..CATCH statement, it immediately executes the statement included in the TRY clause. If the TRY statement executes successfully, SQL Server simply moves on. On the other hand, if your TRY statement generates an error, SQL Server executes the CATCH statement to gracefully handle the error.
Read more: Using TRY…CATCH to Handle SQL Server Errors
TRY..CATCH works by allowing you to specify two Transact-SQL statements: one that you wish to "try" and another that you wish to use to "catch" any errors that might arise. When SQL Server encounters a TRY..CATCH statement, it immediately executes the statement included in the TRY clause. If the TRY statement executes successfully, SQL Server simply moves on. On the other hand, if your TRY statement generates an error, SQL Server executes the CATCH statement to gracefully handle the error.
Read more: Using TRY…CATCH to Handle SQL Server Errors


No comments yet. Leave a Comment