SwitchUp SwitchUp Ranked Best Coding Bootcamps 2025

Rescuing Multiple Exception Types in Ruby

Altcademy Team wrote on 7 February 2018

Normally, you can rescue a type of exceptions like this
begin [] + '' rescue TypeError => e puts "oops: #{e.message}" end

And, you can also catch multiple types of exceptions like this
begin rand(2) == 0 ? ([] + '') : (foo) rescue TypeError, NameError => e puts "oops: #{e.message}" end


Trusted by

Students and instructors from world-class organizations

Join the upcoming Cohort #111

Enroll for March 2nd, 2026