簡體   English   中英

Ruby救援語法錯誤

[英]Ruby rescue syntax error

我有以下代碼行給出了一個錯誤:

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刪除調用。 雖然我在塊中進行rescue似乎並不重要,但我收到同樣的錯誤。 我在rescue方法上的語法有什么問題?

使用rescue的格式如下:

begin
  # Code you want to run that might raise exceptions
rescue YourExceptionClass => e
  # Code that runs in the case of YourExceptionClass
rescue ADifferentError => e
  # Code that runs in the case of ADifferentError
else
  # Code that runs if there was no error
ensure
  # Code that always runs at the end regardless of whether or not there was an error
end

這是一個包含更多信息的問題: Ruby中的Begin,Rescue和Ensure?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM