我如何在Ruby on Rails代码中捕获Zlib :: BufError? [英] How can I catch Zlib::BufError in my Ruby on Rails code?
问题描述
Geocoder.search(address)
这个工作非常好,我可以解析JSON的响应。但是当我离开脚本运行时,有时会出现以下错误:
Zlib :: BufError:缓冲区错误
而不是脚本掉下来,我想抓住这个错误并继续执行脚本。我怎么能用Ruby呢?
确保 Zlib
可用,您需要在要获取错误的文件中 require'zlib'
。它不像 Geocoder
已经声明为任何地方的依赖项,所以当您的拯救
行正在评估。
require'zlib'
begin
Geocoder.search ('110 William St,28th New York,NY 10038')
rescue Zlib :: BufError =>
put'Stack Overflow似乎已经移动'
end
I have built an app with Rails. I have a large list of addresses which I am standardizing via the Bing/Google API using Geocoder. This is my current call to get the adddress info:
Geocoder.search(address)
This works perfectly fine and I can parse the response JSON. However when I leave the script running it sometimes falls over with the following error:
Zlib::BufError: buffer error
Instead of the script falling over I would like to catch this error and continue with the script. How could I do this with Ruby? I am not sure which exception to catch, if any.
To ensure Zlib
is available, you need to require 'zlib'
in the file where you want to catch the error. It doesn't look like Geocoder
has declared that as a dependency itself anywhere, so it may not be loaded when your rescue
line is being evaluated.
require 'zlib'
begin
Geocoder.search('110 William St, 28th Floor New York, NY 10038')
rescue Zlib::BufError => boom
puts 'Stack Overflow appears to have moved.'
end
这篇关于我如何在Ruby on Rails代码中捕获Zlib :: BufError?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!