samedi 28 février 2015

Try/Catch fails to catch exception in stored procedure


Vote count:

0




I'm struggling to get my try/catch to work with my stored procedure, it seems to not catch the error. I've been searching around, but no luck. What I'm trying to accomplish is to display the error number if an invalid value, no value, or null is given when the stored procedure is called. I've tried moving the try and catch it feels like everywhere, but it seems like the error may be on the "@SomeID as int" line. I appreciate any help I can get.





alter procedure DeleteAcct
@SomeID as int
as
begin try
declare @counter int
set @counter = (select count(SomeDate) from Table1 where SomeID = @SomeID group by SomeID)
begin
if(@counter > 0)
begin
Print 'Testing'
end
else
begin
delete from Table2
where SomeID = @SomeID
Print 'Delete successful'
end
end
end try
begin catch
print error_number()
end catch

<!-- calling the stored procedure -->
exec DeleteAcct '1231231231221'

<!-- Error received -->
Msg 8114, Level 16, State 5, Procedure DeleteAcct, Line 0
Error converting data type varchar to int.




asked 1 min ago







Try/Catch fails to catch exception in stored procedure

Aucun commentaire:

Enregistrer un commentaire