April 21, 2015

Try catch in SQL Server

What will be the output of below script?

BEGIN TRY
       SELECT 1/0
       SELECT 'Try Catch Test'
END TRY
BEGIN CATCH
              SELECT ERROR_NUMBER() AS ErrorNumber
     ,ERROR_SEVERITY() AS ErrorSeverity
     ,ERROR_STATE() AS ErrorState
     ,ERROR_LINE() AS ErrorLine
     ,ERROR_MESSAGE() AS ErrorMessage;
END CATCH


After exception it will go to catch block.
And Output:

image

No comments:

Post a Comment