s.ross:
> Do you expect your C
> runtime library to raise an exception when an fwrite fails? No, it
> returns an error code and you handle it because, as a programmer, you
> know that conditions like disk full or permission denied can happen.
> Same in Ruby.

This is factually challenged.

irb(main):028:0> f.readline
EOFError: end of file reached
        from (irb):28:in `readline'
        from (irb):28

irb(main):001:0> f = File.open("testfile", "w")
Errno::EACCES: Permission denied - testfile
        from (irb):1:in `initialize'
        from (irb):1:in `open'
        from (irb):1

The reason C uses return codes is because exceptions were not a
language feature when those libraries were developed, not because they
are good thing.

The problem with return codes in this situation is that only one thing
can go write, but nearly infinite things can go wrong.  Exceptions
pass back specific information about exactly what went wrong and
where, including references, messages, etc.

Certainly the database raise exceptions when data is invalid.

Another idea if you must avoid exceptions:

Make save return an exception on invalid data.

If you don't want an exception raised, call:

if user.valid?
  user.save!
end

The ! ensures validation is not run a second time, and that a changed
validation state won't result in a save failure.  You can safely not
check the return value (since the database will throw an exception if
the write fails - and DataMapper lets that bubble up).

The current code reminds me of this:

begin
  do_something_risky
rescue
  return false
end

Bye bye any information about what went wrong, and good luck tracking
it down.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to datamapper@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to