Подтвердить что ты не робот

Как отобразить тип ошибки в рубине?

в следующем коде

begin
 raise StandardError, 'message'
 #some code that raises a lot of exception
rescue StandardError
 #handle error
rescue OtherError
 #handle error
rescue YetAnotherError
 #handle error
end

Я хочу напечатать предупреждение с указанием типа и сообщения об ошибке без добавления инструкции печати к каждому из предложений о спасении, например

begin
 raise StandardError, 'message'
 #some code that raises a lot of exception
rescue StandardError
 #handle error
rescue OtherError
 #handle error
rescue YetAnotherError
 #handle error
???
 print "An error of type #{???} happened, message is #{???}"
end
4b9b3361

Ответ 1

begin
  raise ArgumentError, "I'm a description"
rescue Exception => ex
  puts "An error of type #{ex.class} happened, message is #{ex.message}"
end

Отпечатки: ошибка типа ArgumentError произошла, сообщение - это описание