those two pieces of code results in the same error thrown given a condition:
function f1(x)
if x > 2
return x
else
return error("x <= 2")
end
end
function f2(x)
if x > 2
return x
else
throw(error("x <= 2"))
end
end
both f1 and f2 errors when x <= 2, but i can´t find any differences in why prefer one over the another. going further, these 3 pieces of code return the same:
error(2)
throw(2)
throw(error(2))
is there any guides on how to use throw vs return an error directly?