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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Manas MohapatraRank #182 · 13.2K reputationPosted Dec 2, 2015, 6:31 AM EST
Jignesh TrivediRank #16 · 50.3K reputationPosted Dec 2, 2015, 6:10 PM EST
Vipan SharmaRank #1,589 · 999 reputationPosted Dec 2, 2015, 6:45 PM EST
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