Ruby救援语法错误

Ruby救援语法错误,第1张

概述我有以下代码行给出了一个错误: rescue Timeout::Error => e logs.puts("Rescued a timeout error...#{e}") email_ids_all.each do |email_delete| call= "/api/v2/emails/#{email_delete}/" uri= HTTParty.d 我有以下代码行给出了一个错误:

rescue Timeout::Error => e    logs.puts("Rescued a timeout error...#{e}")    email_IDs_all.each do |email_delete|      call= "/API/v2/emails/#{email_delete}/"      uri= httparty.delete("https://www.surveys.com#{call}",:basic_auth => auth,:headers => { 'ContentType' => 'application/x-www-form-urlencoded','Content-Length' => "0" }      )      puts "Deleted email #{email_delete}".green      log.puts("Deleted email #{email_delete}")    end    abort #abort entire script after deleting emails  end

我收到的错误是这样的:

Syntax error,unexpected keyword_rescue,expecting $end  rescue Timeout::Error => e        ^

基本上我只是尝试在脚本超时时运行API删除调用.虽然我在块中进行救援似乎并不重要,但我收到同样的错误.我在救援方法上的语法有什么问题?

解决方法 使用救援的格式如下:

begin  # Code you want to run that might raise exceptionsrescue YourExceptionClass => e  # Code that runs in the case of YourExceptionClassrescue ADifferentError => e  # Code that runs in the case of ADifferentErrorelse  # Code that runs if there was no errorensure  # Code that always runs at the end regardless of whether or not there was an errorend

这是一个有更多信息的问题:Begin,Rescue and Ensure in Ruby?.

总结

以上是内存溢出为你收集整理的Ruby救援语法错误全部内容,希望文章能够帮你解决Ruby救援语法错误所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1257657.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-07
下一篇 2022-06-07

发表评论

登录后才能评论

评论列表(0条)

保存