begin
do_something_error_prone
rescue AParticularKindOfError
# Insert heroism here.
rescue
write_to_error_log
raise
end
而多个 catchs 需要嵌套..。
catch :foo do
catch :bar do
do_something_that_can_throw_foo_or_bar
end
end
A bare rescue is equivalent to rescue StandardError and is an idiomatic construct. A "bare catch", like catch() {throw :foo}, will never catch anything and shouldn't be used.