Lyle Johnson
4/2/2008 9:18:00 PM
On Wed, Apr 2, 2008 at 4:08 PM, Brendan Stennett <brendan6@gmail.com> wrote:
> How do I alert an error if it occurs in an object's constructor?
Raise an exception.
class Zip
def initialize(zipcode)
o = Zipcode.find_by_zipcode(zipcode)
if o.length == 0
raise ArgumentError, "no zip code specified"
else
@zipcode = zipcode
end
end
end
begin
o = Zip.new('00000')
rescue ArgumentError
# deal with the error here
end
Hope this helps,
Lyle