SQL Server 2012 provides the
TRY...CATCH construct, which you can use within your T-SQL stored procedures to provide a more graceful mechanism for exception handling than was available in previous versions of SQL Server by checking
@@ERROR (and often the use of
GOTO statements) after each SQL statement.
TRY...CATCH construct consists of two parts: a
TRY block and a
CATCH block. When an error condition is detected in a T-SQL statement inside a
TRY block, control is immediately passed to a
CATCH block, where the error is processed. T-SQL statements in the
TRY block that follow the statement that generated the error are not executed.
If an error occurs and processing is passed to the
CATCH block, after the ...