# Error is not skipped by next in a each loop

**URL:** <https://www.ruby-forum.com/t/error-is-not-skipped-by-next-in-a-each-loop/258905>\
**Category:** Uncategorized\
**Created:** [March 17, 2020, 12:06pm UTC](https://www.ruby-forum.com/t/error-is-not-skipped-by-next-in-a-each-loop/258905 "2020-03-17T12:06:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![groschat](https://www.ruby-forum.com/user_avatar/www.ruby-forum.com/groschat/32/2347_2.png) [@groschat](https://www.ruby-forum.com/u/groschat)\
**Post date:** [March 17, 2020, 12:06pm UTC](https://www.ruby-forum.com/t/error-is-not-skipped-by-next-in-a-each-loop/258905/1 "2020-03-17T12:06:09Z")

</div>

Hello everyone,

\*edit: ‘at’ =@ (the ‘at sign’ is somewhat understood as mentioning an user). Formatting also returns an error. I am sorry for that. I don’t know how to solve this

I am new to ruby. I have a ‘for each’ loop for which I would like errors to be ignored so ot goes to the next item.  
Yet, I must be missing something. Has somebody an idea?

require ‘selenium-webdriver’  
require ‘rspec/expectations’  
include RSpec::Matchers

def setup  
'at’driver = Selenium::WebDriver.for :firefox  
end

def teardown  
'at’driver.quit  
end

def run  
setup  
yield  
teardown  
end

run do  
require ‘rest-client’

'at’driver.get ‘[Women's Unlined Bras & Lace Bralettes | Cotton On](https://cottonon.com/SG/women/womens-lingerie/bras/unlined-bras/)’  
all\_images = @driver.find\_elements(tag\_name: ‘img’)

all\_images.each do |img|  
begin  
RestClient.get img.attribute(‘src’) do |response, request, result|  
if response.code ==404  
puts img.attribute(‘src’)  
end  
rescue  
next img  
end  
end  
end

end
