Basic TRY/CATCH : Try catch « Transact SQL « SQL Server / T-SQL Tutorial






5> BEGIN TRY
6>     SELECT 1/0 AS DivideByZero
7> END TRY
8> BEGIN CATCH
9>     SELECT 'Exception Caught!' AS CatchMessage
10> END CATCH
11> GO
DivideByZero
------------

(0 rows affected)
CatchMessage
-----------------
Exception Caught!

(1 rows affected)
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