From: "Mauricio Fernández" Date: 2003-05-20T16:05:14+09:00 Subject: Re: Exceptions in initialize()? On Tue, May 20, 2003 at 03:30:58PM +0900, Jack Twilley wrote: > I'm very new to ruby, so please be gentle. > > I have created a class and an initialize() method. I would like an > attempt to initialize() to fail if either an argument is not supplied > or the supplied argument does not match a regular exponent. The > solution would appear to be to use an exception, but I cannot tell > - From the documentation what happens if an exception is thrown from > within an initialize() method and not caught. > > I know I can "just try it", but I'm interested in knowing what's > supposed to happen in that case. I'm hoping that what is supposed to > happen is that the new object is equal to nil, but I can't be sure of > the defined behavior until it's defined. >> class Foo; def initialize; raise "foo"; end; end => nil >> a = Foo.new rescue nil => nil >> a => nil or >> def Foo.new(*args) >> begin ?> super(*args) >> rescue >> nil >> end >> end => nil >> a = Foo.new => nil -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com There are 3 kinds of people: those who can count & those who can't. -- Unknown source