From: "Stephan Kämper" Date: 2002-04-04T22:31:44+09:00 Subject: Re: Test the result of an initialization ? Jayce Piel wrote: > > Yohanes Santoso wrote: > > > jayce@mosx.net (Jayce Piel) writes: > > > > > What I want is if the path is not a path to a file, the object is not > > > created. I try to do a "return nil" in initialize, but it has no effect. > > > > class ArchiveFile > > def initialize(filename) > > if not File.stat(filename).file? > > raise "#{filename} is not a valid file" > > end > > end > > end > > Hmmm... > But the fact remains... Where must I put the catch ? Nowhere... In Ruby you 'raise' exceptions and handle them in a begin/rescue/retry/ensure/end construct. Check the freely available online pickaxe book for all the information. Only (?) if you use 'throw' there's something to 'catch'. Seems reasonable, in fact! But this is _not_ to be confused with exceptions (and also explaind in the online version of the pickaxe book -> http://www.rubycentral.com/downloads/book.html ) HTH & happy rubying Stephan