Sorry for the previous sentence. I just noticed the actual cause of the error. The following works as you would expect:
def doCalc
begin
print( "Enter a number: " )
aNum = gets().chomp()
result = 100 / aNum.to_i
rescue => e
result = 0
puts( "Error: #{e}\nPlease try again." )
retry
else
msg = "Result = #{result}"
ensure
msg = "You entered '#{aNum}'. " + msg
end
return msg
end
You actually had three errors occurring one after another.
The first mistake that occurred as you planned was during parsing and dividing. And he was correctly caught rescue Exception => e.
"" "" "". "asd" + e + "asd" , , "". , "" , , - , ensure .
ensure msg , msg nil . , , .
: , add-exception-to-a-string . e. , e.to_s .