gpt4 book ai didi

ruby-on-rails - 遇到错误后使 Ruby/Rails 继续方法

转载 作者:数据小太阳 更新时间:2023-10-29 07:41:47 27 4
gpt4 key购买 nike

def checkdomains
@domains = Domain.all

#@domains.where(:confirmed => "yes").each do |f|
@domains.each do |f|
r = Whois.whois(f.domain)
if r.available? == true
EmailNotify.notify_email(f).deliver
end
end
end

此方法在遇到无效 url 时崩溃(whois gem 给出错误),并且不会继续检查其余域。有什么方法可以让它继续检查其余域,即使它在一个域上崩溃了?至少在我能够解决每个域的钓鱼问题之前是这样。

最佳答案

  @domains.each do |f|
begin
r = Whois.whois(f.domain)
if r.available? == true
EmailNotify.notify_email(f).deliver
end
rescue Exception => e
puts "Error #{e}"
next # <= This is what you were looking for
end
end

关于ruby-on-rails - 遇到错误后使 Ruby/Rails 继续方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6990808/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com