2009年3月2日月曜日

RubyのException

今さらながら、rescueでExceptionを捕捉してraiseする場合でも
ちゃんと、ensureは実行される。
raise以降のやつはもちろん走らない

begin
begin
raise Exception
rescue Exception
p 'Hello'
raise Exception
p 'Hello2'
ensure
p 'Yahoo'
end
rescue Exception
p 'Finish'
end

-- Result --
"Hello"
"Yahoo"
"Finish"

0 件のコメント:

コメントを投稿