When I drew the exception handling of Ruby, it was necessary to use it properly according to the situation, so I summarized it as a memorandum.
begin rescue
begin
1 / 0 //Raise an exception
rescue
puts "An error has occurred"
end
raise
begin
raise
rescue
puts "An error has occurred"
end
retry
begin
raise
rescue
retry //Re-execute begin processing
end
ensure
begin
//Normal processing
rescue => e
//Exception handling
ensure
//It will be executed for the time being
end
Recommended Posts