What way is true?

Hello.

I have some method. What is preferable: use raise and rescue or use
return?

def(a, b)
  # ...
  rescue "some error" if some_is_wrong

rescue
  another_method
  false
end

or

def(a, b)
  # ...
  if some_is_wrong
    another_method
    false
  end
end

···

--
Posted via http://www.ruby-forum.com/.

Yan Bernatsky 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