Best practice: raise an exception or return false

just wondering how others deal with invalid/illegal operations on their
models?

until now, I’ve simply been returning true or false depending on wether
or
not the operation succeeded, but that doesn’t tell the calling function
why
the operation failed (if it failed).

I could use custom exceptions, but is it good practice to raise an
exception
on every invalid action or just the more serious ones? where’s the best
place to store custom exceptions? I’m thinking model specific ones in
the
model file itself and generic ones in environment.rb…?

how do others deal with this?
alan

Raise exceptions. They’re much harder miss. :slight_smile:


– Tom M.

+1 for exceptions. It forces you to handle the errors.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs