Hello.
I have some method. What is preferable: use raise and rescue or use
return?
def(a, b)
…
raise “some error” if some_is_wrong
rescue
another_method
false
end
or
def(a, b)
…
if some_is_wrong
another_method
false
end
end
Hello.
I have some method. What is preferable: use raise and rescue or use
return?
def(a, b)
raise “some error” if some_is_wrong
rescue
another_method
false
end
or
def(a, b)
if some_is_wrong
another_method
false
end
end
Yan B. wrote:
Hello.
I have some method. What is preferable: use raise and rescue or use
return?
In the example you’ve given, I’d use return most certainly, since you
return false either way. Exceptions are great for ‘out of band’
notification of callers that something went wrong, not when the outcome
is expected and has a return value allocated for it.
http://ruby-doc.org/docs/ProgrammingRuby/html/tut_exceptions.html
kaspar
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs