Today I Learned

Passing multiple exceptions to rescue

To rescue multiple classes of exceptions, you have to pass them as a list to rescue method. Passing as an array won’t work, unless you prefix it with * (effectively breaking it into a list)

# Works
begin
  # some code here    
rescue ExceptionA, ExceptionB
  puts "uff, thanks!"
end

# Doesn't work
begin
  # some code here    
rescue [ExceptionA, ExceptionB]
  puts "uff, thanks!"
end

# Works
EXCEPTIONS = [ExceptionA, ExceptionB]
begin
  # some code here    
rescue *EXCEPTIONS
  puts "uff, thanks!"
end