Ответ 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 произошла, сообщение - это описание
в следующем коде
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
begin
raise ArgumentError, "I'm a description"
rescue Exception => ex
puts "An error of type #{ex.class} happened, message is #{ex.message}"
end
Отпечатки: ошибка типа ArgumentError произошла, сообщение - это описание