Chapter 6. Error Handling

Itzik Ben-Gan

When you develop T-SQL code, you need to take into consideration situations in which your code might fail. SQL Server provides you with tools to handle errors and take corrective measures. The area of error handling with T-SQL was improved dramatically only recently. SQL Server 2005 introduced the TRY/CATCH constructs, which was a big leap forward. Even though some important aspects of error handling in T-SQL are still missing, SQL Server 2008 did not add any improvements in this area. I hope that the next major release of SQL Server will add more features and improvements in this area.

To help you appreciate the benefits of using the TRY/CATCH construct I’ll first describe the problematic nature of handling ...

Get Inside Microsoft® SQL Server® 2008: T-SQL Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.