RosettaCodeData/Task/Exceptions/Ruby/exceptions-3.rb

12 lines
176 B
Ruby
Raw Permalink Normal View History

2013-04-10 16:57:12 -07:00
# raise (throw) an exception
def spam
raise SillyError, 'egg'
end
# rescue (catch) an exception
begin
spam
rescue SillyError => se
puts se # writes 'egg' to stdout
end