Chapter 12 - Exceptions
Exercise 2: Handling the exception object
The call to send_sos
raises an exception with a message containing some coordinates. Rescue the exception, and print “Sending rescue party to” followed by the coordinates in the exception message.
def send_sos
raise "Latitude -50.75, Longitude 166.04"
end
begin
send_sos
rescue => exception
puts "Sending rescue party to #{exception.message}"
end
Here’s the output:
Sending rescue party to Latitude -50.75, Longitude 166.04