def foo
raise StandardError, "I like Ruby" if rand < 0.5
end
begin
foo # exception might get raised here
rescue StandardError
print "StandardError was raised: $!\n"
rescue
print "Some other exception was raised: $!\n"
else
print "No exception was raised\n"
ensure
print "This code gets called no matter what\n"
end
|