開発環境
- OS X El Capitan - Apple (OS)
- Emacs (Text Editor)
- Ruby 2.3 (プログラミング言語)
Head First Ruby (Jay McGavren (著)、O'Reilly Media)のChapter 12.(Exceptions: Handling the Unexpected)、Trying again after an error with "retry"、EXERCISE(No. 6431))を取り組んでみる。
EXERCISE(No. 6431))
コード(Emacs)
#!/usr/bin/env ruby2.3
# -*- coding: utf-8 -*-
class TestScoreError < StandardError
end
score = 52
begin
if score > 60
puts "passing grade"
else
raise TestScoreError, "failing grade"
end
rescue TestScoreError => error
puts "Received #{error.message}. Taking make-up exam..."
score = 63
retry
end
入出力結果(Terminal)
$ ./sample2.rb Received failing grade. Taking make-up exam... passing grade $
0 コメント:
コメントを投稿