Aniket Narvankar

Aniket Narvankar

  • 551
  • 2.1k
  • 608.5k

Error Handling in Sql

Aug 18 2016 7:31 AM
I want to handle error while insertion in the table if wrong value is inserted it will throw an error,for this I have written following stored procedure 
 
 
ALTER PROCEDURE [dbo].[Insert_Update_Test]
(
@Para varchar(50)='',
@Name varchar(50)='',
@Id int = 0
)
AS
BEGIN
Begin Try
If @Para = 'ADD'
Begin
Insert into tblTesters (Name,Id) values (@Name,@Id)
END
End Try
Begin Catch
Select ERROR_NUMBER()
END Catch
END
If I am Executing this Store Procedure 
EXEC Insert_Update_Test 'ADD','1','Aniket'
If am passing value varchar to integer parameter @Id,but catch blog is not getting executed even if there is error while insertion
Please do let me know about the solution I am stuck upon this