Javaじゃこんなコード書けない
よね?
def with_error_handling begin yield rescue Exception puts "error!!" end end with_error_handling { result = 10 / 2 puts result } with_error_handling { result = 10 / 0 # zero divide puts result }
で。Javaとかだとこんな感じ*1。エラーハンドリング部のコードの重複が切ない。
begin result = 10 / 2 puts result rescue Exception puts "error!!" end begin result = 10 / 0 # zero divide puts result rescue Exception puts "error!!" end
ちなみに。結果はこんな感じ。
5 error!!
On Lisp (PDF)で Paul Grahamに教えてもらったんです。
DEEP BLUE - 映画館と映画作品情報をお知らせ
のDVDが5/27発売とのこと。ちょっぴり気になり―の。