Exceptions handling using try….Catch in MS SQL 2005(codegroups.com)
submitted by
shaileshk(20) 4 years ago
Exceptions handling using try….Catch in MS SQL 2005
Microsoft Add new feature ‘Try…Catch’ in MS SQL 2005.
You can exception handling in MS SQL 2005 using the Try Catch.
If divide by zero exception then returns the error is ‘Divide by Zero error encountered.
i.e
Declare @i int,@j int
Select @i=200,@j=0
Select @i/@j
Print @@Error
Run this query in Query analyzer. you will get the error message Divide by Zero error
encountered.
Syntex for Try….Catch
BEGIN TRY
END TRY
BEGIN CATCH
END CATCH
DECLARE
@i int , @j int
SELECT @i =100, @j =0
BEGIN TRY
SELECT @i/@j
END TRY
BEGIN CATCH
SELECT ERROR_NUMBER() as ErrorNo,
ERROR_MESSAGE() as ErrMessage
END CATCH
|category: Database
|Views: 39
tags:
Database another
Everyones tags:
Your Tags: