![]() ![]() If the CATCH block contains a nested TRY.CATCH construct, any error in the nested TRY block will pass control to the nested CATCH block. For example, a CATCH block can contain an embedded TRY.CATCH construct to handle errors encountered by the CATCH code.Įrrors encountered in a CATCH block are treated like errors generated anywhere else. Either a TRY block or a CATCH block can contain nested TRY.CATCH constructs. If any part of the error information must be returned to the application, the code in the CATCH block must do so by using mechanisms such as SELECT result sets or the RAISERROR and PRINT statements. If the END CATCH statement is the last statement in a stored procedure or trigger, control is passed back to the statement that called the stored procedure or fired the trigger.Įrrors trapped by a CATCH block are not returned to the calling application. When the code in the CATCH block finishes, control passes to the statement immediately after the END CATCH statement. If there is an error in the code that is enclosed in a TRY block, control passes to the first statement in the associated CATCH block. If there are no errors in the code that is enclosed in a TRY block, when the last statement in the TRY block has finished running, control passes to the statement immediately after the associated END CATCH statement. For example, a TRY.CATCH construct cannot span two BEGIN.END blocks of Transact-SQL statements and cannot span an IF.ELSE construct. A TRY.CATCH construct cannot span multiple blocks of Transact-SQL statements. Including any other statements between the END TRY and BEGIN CATCH statements generates a syntax error.Ī TRY.CATCH construct cannot span multiple batches. RemarksĪ TRY.CATCH construct catches all execution errors that have a severity higher than 10 that do not close the database connection.Ī TRY block must be immediately followed by an associated CATCH block. ArgumentsĪny group of Transact-SQL statements in a batch or enclosed in a BEGIN.END block. To view Transact-SQL syntax for SQL Server 2014 (12.x) and earlier versions, see Previous versions documentation. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |