Hi,
I've got a stored procedure where I need to convert values to an int. If the data can't be converted, SQL is throwing an error that I can't catch in the stored procedure. Here is some example code:
DECLARE @ID int
DECLARE @err int
SET @ID = 12
SET @ID = cast('CauseError' as int) --Causes an Error
SELECT @err = @@error
IF @err <> 0
BEGIN
print 'error' --NEVER GETS HERE!
SET @ID = 0
END
select @ID
None of the code after the line with the error is run. Can anyone tell me how to catch this error inside the stored procedure so I can handle it there?
Thanks,
I've got a stored procedure where I need to convert values to an int. If the data can't be converted, SQL is throwing an error that I can't catch in the stored procedure. Here is some example code:
DECLARE @ID int
DECLARE @err int
SET @ID = 12
SET @ID = cast('CauseError' as int) --Causes an Error
SELECT @err = @@error
IF @err <> 0
BEGIN
print 'error' --NEVER GETS HERE!
SET @ID = 0
END
select @ID
None of the code after the line with the error is run. Can anyone tell me how to catch this error inside the stored procedure so I can handle it there?
Thanks,