RosettaCodeData/Task/Exceptions/Ruby/exceptions-3.rb
2023-07-01 13:44:08 -04:00

11 lines
176 B
Ruby

# 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