TRY/CATCH Statement

Executes the statement-to-try statements until successful completion or until one of the statements throws an error. If an error is thrown, then the statement-if-error statements are executed. The statements in the CATCH block may use the ERROR_MESSAGE function to access the thrown message.

Syntax

BEGIN TRY
    [statement-to-try]
    ...
END TRY
BEGIN CATCH
    [statement-if-error]
    ...
END CATCH

Parameters

Example

-- Prints "Foo".
BEGIN TRY
THROW 'Foo';
END TRY
BEGIN CATCH
PRINT ERROR_MESSAGE();
END CATCH