Applying TRY...CATCH Error Handling Without Recoding a Stored Procedure : Try catch « Transact SQL « SQL Server / T-SQL Tutorial






5> CREATE PROCEDURE usp_SEL_DivideByZero
6> AS
7> SELECT 1/0
8> GO
1>
2> BEGIN TRY
3> EXEC dbo.usp_SEL_DivideByZero
4> END TRY
5> BEGIN CATCH
6> SELECT ERROR_NUMBER() ErrorNBR, ERROR_SEVERITY() Severity,
7> ERROR_LINE () ErrorLine, ERROR_MESSAGE() Msg
8> PRINT 'This stored procedure did not execute properly.'
9> END CATCH
10> GO

-----------

(0 rows affected)
ErrorNBR    Severity    ErrorLine   Msg

































----------- ----------- ----------- ------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------
       8134          16           5 Divide by zero error encountered.


































(1 rows affected)
This stored procedure did not execute properly.
1>








20.23.Try catch
20.23.1.Error Handling in SQL Server 2005
20.23.2.Error Handling with TRY...CATCH
20.23.3.try...catch Demo
20.23.4.Basic TRY/CATCH
20.23.5.Another TRY/CATCH
20.23.6.Nesting TRY...CATCH Calls
20.23.7.Applying TRY...CATCH Error Handling Without Recoding a Stored Procedure