Created
January 24, 2016 10:19
-
-
Save taisyo7333/dde0b54e053ecc867c75 to your computer and use it in GitHub Desktop.
Ruby Exception [retry]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding: SJIS | |
a = 0 | |
begin | |
b = 1 / a | |
rescue ZeroDivisionError | |
a += 1 | |
retry | |
ensure | |
p b | |
end | |
# => 1 | |
# ensure calls only once. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>ruby Code3-163.rb | |
ruby Code3-163.rb | |
1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment