Sample code for catch error
BEGIN TRY
EXECUTE Abc
END TRY
BEGIN CATCH
print 'Error got'
SELECT
ERROR_NUMBER() as ErrorNumber,
ERROR_MESSAGE() as ErrorMessage;
END CATCH;
If you follow the following, this will not work.
CREATE PROC test
AS
BEGIN TRY
SELECT * FROM NonexistentTable
END TRY
BEGIN CATCH
END CATCH
The only way this works is if you have one stored procedure, call another stored procedure, such as:
CREATE PROC Test
AS
SELECT * FROM NonexistentTable
GO
CREATE PROC test2
AS
BEGIN TRY
EXECUTE Test
END TRY
BEGIN CATCH
END CATCH
GO
TRY ... CATCH constructs do not capture the following conditions:
Alerts or informational messages with a severity of 10 or lower.
20 , SQL Server Database Engine . 20 , , TRY... CATCH .
, .
KILL.
CATCH, , TRY... CATCH: