为什么会引发异常?

时间:2015-03-27 15:53:27

标签: ruby exception raise

def calcUnits(units)
if(units < 0 or units > 20)
    raise "error"
end
end

def calcSession(session)
if(session < 0 or session > 3)
    raise "error 2"
end
end

enrollFee1 = 46.00 # enrollment fee per unit for california residents
enrollFee2 = 325.00  # enrollment fee per unit for non-residents

studentServFee1 = 48.50 # student service fee for winter/summer semester
studentServFee2 = 51.50 # student service fee for fall/spring semester

stickerFee = 19.50
idCard = 13.00

parkingFee1 = 45.00
parkingFee2 = 85.00 


begin

print "Enter number of units enrolled: "
units1 = gets.chomp.to_i

print "Is this Fall[0], Winter[1], Spring[2], or Summer[3] seassion: "
session1 = gets.chomp.to_i

calcUnits(units1)
calcSession(session1)

rescue 

puts "Sorry but one of your inputs was invalid"

ensure 

puts "Thank you for using SMC fee calculator program in ruby"

end

如果我输入的值为14且会话值为1,为什么我的输入不应该引发异常。

我试图解决这个问题并尝试更改条件语句,但没有任何效果。我是红宝石的新手,我很感激能得到的所有帮助。

0 个答案:

没有答案