Listing 4: Template for Calling Stored Procedures to Test For Trappable and Untrappable Errors DECLARE @error_stat int, @return_stat int EXEC @return_stat = proc_1 @param1 = 1, @param2 = 'ab' SET @error_stat = @@ERROR -- Non-zero if untrappable error occurred in stored procedure. IF @return_stat <> 0 OR @error_stat <> 0 BEGIN IF @@trancount <> 0 -- Roll back any open transaction. rollback tran IF @error_stat <> 0 -- Return any untrappable error code. RETURN @error_stat ELSE -- Return any trappable error code. RETURN @return_stat END