I'm having a problem with TRY...CATCH blocks. Can someone explain why the following code will not execute my sp?
DECLARE @Result int
SET @Result = 0
BEGIN TRY
SELECT * FROM TableNoExist
END TRY
BEGIN CATCH
SET @Result = ERROR_NUMBER()
END CATCH
EXEC dbo.spSecurityEventAdd @pSecurityEventTypeID = 11, @pResult = @Result
But this code does work:
DECLARE @Result int
SET @Result = 0
BEGIN TRY
SELECT 1/0
END TRY
BEGIN CATCH
SET @Result = ERROR_NUMBER()
END CATCH
EXEC dbo.spSecurityEventAdd @pSecurityEventTypeID = 11, @pResult = @Result
I'd like to make sure I catch all errors. Thanks