Hi All,
Please can any one explain how to do Error handling in sqlserver?
can any one explain with one realtime scenario....
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Vipan SharmaPosted Dec 2, 2015, 11:45 PM
BEGIN TRY
--T-SQL statements
--or T-SQL statement blocks
END TRY
BEGIN CATCH
--T-SQL statements
--or T-SQL statement blocks
END CATCH
DECLARE @num INT, @msg varchar(200)
---- Divide by zero to generate Error
SET @num = 5/0
PRINT 'This will not execute'
END TRY
BEGIN CATCH
PRINT 'Error occured that is'
set @msg=(SELECT ERROR_MESSAGE())
print @msg;
END CATCH
GO
Jignesh TrivediPosted Dec 2, 2015, 11:10 PM
Manas MohapatraPosted Dec 2, 2015, 11:31 AM