ライブラリの内部から素のRuntimeErrorが飛んでくると対処に困りますね。
適当な例外クラスを用意してほしいものですが、とりあえず以下のような関数を定義することで、特定のメッセージの場合だけrescueできます。
ruby>>
def RuntimeError(message)
($!.is_a?(RuntimeError) and $!.message == message) ? RuntimeError : Class
end
begin
do something
rescue RuntimeError('connection closed by server') => e
...
end
<<--
posted by
genki on Tue 29 Jul 2014 at 10:58 with 0 comments