C
cap
http://www.awprofessional.com/bookstore/product.asp?isbn=0672328844&rl=1
The "The ruby way" book said
but actually, I found the "else" clause is only executed when there is
no exception been thrown,such as :
-------------------------
begin
puts "do something"
rescue NameError
puts "name error #{$!}"
else
puts "else #{$!}"
end
--------------------------
the result is
-------------------
do something
else
------------------
so the "else" clause is useless because we can simply put the content
of "else" caluse to the last line in the "begin" block before the first
"rescue"
Am I wrong or the book is wrong?
my ruby version is
ruby 1.8.4 (2005-12-24) [i686-linux]
The "The ruby way" book said
In the event that error types are specified, it may be that an
exception does not match any of these types. For that situation, we are
allowed to use an else clause after all the rescue clauses.
begin
# Error-prone code...
rescue Type1
# ...
rescue Type2
# ...
else
# Other exceptions...
end
but actually, I found the "else" clause is only executed when there is
no exception been thrown,such as :
-------------------------
begin
puts "do something"
rescue NameError
puts "name error #{$!}"
else
puts "else #{$!}"
end
--------------------------
the result is
-------------------
do something
else
------------------
so the "else" clause is useless because we can simply put the content
of "else" caluse to the last line in the "begin" block before the first
"rescue"
Am I wrong or the book is wrong?
my ruby version is
ruby 1.8.4 (2005-12-24) [i686-linux]