Hi all. I’m writing a script to make a job a little bit easier, and it may be something I share with others so I’m trying to put a bit more care into making it. I’m not very familiar with error handling and I’m struggling with the control flow. How do I get the script to retry the failed action instead of quitting the process entirely? Most of the code presented works, except for the part where try/catch comes in. When those are touched, the script breaks.
# radius_roll will be the approx. measured radius of the roll, measured before unrolling
# thickness_band will be the meausured thickness of the band in the direction of the groove, measured before unrolling; b in the archimedian spiral equation.
# tau represents the circle constant, where tau/2 = pi. Equal to one revolution of a point a point some distance from the origin
# n will be the number of coils on the roll
# length will be the calculated length of the roll
# radius_axle will be the radius of the hole in the center of the roll
#Things to consider: freshness of the roll, machine last used on, should probably spit out a short, dated report.
const tau = 2*π
trigger = false
# the math doesn't change, this is for redundancy.
println("Choose your units: inches (\") or centimeters (cm)\n")
ans = readline()
while trigger == false
if ans == "\""
println("Inches selected\n")
global trigger = true
elseif ans == "cm"
println("Centimeters selected\n")
global trigger = true
else
println("Please input a valid unit of measurement from the selection: inches (\") or centimeters (cm)\n")
global ans = readline()
end
end
println("What is the radius of the roll in $ans?\n")
try
global radius_roll = parse(Float64, readline())
catch e0
throw(error("Please input a valid number for the radius of the roll in $ans.\n"))
end
println("You input $radius_roll $ans. Is that correct? Y/N\n")
ans1 = uppercase(readline())
while ans1 != "Y"
if ans1 == "Y"
break
elseif ans1 == "N"
println("What is the radius of the roll in $ans?\n")
try
global radius_roll = parse(Float64, readline())
catch e1
throw(error("Please input a valid number for the radius of the roll in $ans.\n"))
end
println("You input $radius_roll $ans. Is that correct? Y/N\n")
global ans1 = uppercase(readline())
elseif ans1 != "Y" && ans1 != "N"
println("Please input a valid answer: Y/N\n")
global ans1 = uppercase(readline())
end
end