To handle error in SqlServer we can use Try..Catch like below



BEGIN
TRY
'Your Sql Query'
END TRY
BEGIN
CATCH
PRINT 'An error occurred'
END CATCH

If you want to know full information about the Error then you use some function in CATCH block like...


ERROR_NUMBER
()
ERROR_SEVERITY()
ERROR_STATE()
ERROR_PROCEDURE()
ERROR_LINE()
ERROR_MESSAGE()

You can select these function value to know full information about an error. The meaning of these function are given below...