Error handling when running outside of web environment

L.S.,
I have created a rails application which works, I now want to write a
little batch program which uses the different "models" to perform some
tasks. This is what I do:

#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../config/environment'
require 'system'
s = System.new( :name => 'a')
if s.save == false
        print "Error saving\n"
        exit
end

System is a model, has a field "name" which is unique.
class System < ActiveRecord::Base
        validates_uniqueness_of :name
end

When I run the program the second time, I get the "Error saving"
message and the program exits (as expected).

There is no error raised by the save function. If I do no explicit
test, the program just runs on. Is there a way to get better error
handling?

Gr.
Robert

Robert,

   > There is no error raised by the save function. If I do no explicit
   > test, the program just runs on. Is there a way to get better error
   > handling?

use
   save!
instead of save

http://api.rubyonrails.com/classes/ActiveRecord/Base.html#M000906
1397: def save!
1398: save || raise(RecordNotSaved)
1399: end

Thanks!!
New to rails, and ruby but getting into it.
gr.
Robert