Exception Handling in SQL Server 2005

Now that I’ve covered exception handling and exception-handling limitations in SQL Server 2000, I’ll discuss exception handling in SQL Server 2005.

TRY/CATCH

SQL Server 2005 introduces the new TRY/CATCH construct. To use it, you place the suspect code in a BEGIN TRY/END TRY block, followed by a BEGIN CATCH/END CATCH block. When an error is encountered in the TRY block, the error is "trapped," and control is passed to the nearest CATCH block, where you have your exception-handling code. If you trap an error, no error message will be generated and sent to the caller. If you want to throw an error to the caller, you can do so using the RAISERROR command. If no error was generated in the TRY block, the CATCH block ...

Get Inside Microsoft® SQL Server™ 2005 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.