Sat, 14 Sep 2002 03:30:51 +0900, Sean Chittenden <sean / ruby-lang.org> pisze:

> I know there are work arounds, but writing:
> 
> begin
>   Dir.mkdir('/usr')
> rescue Errno::EEXISTS
> end
> 
> begin
>   Dir.mkdir('/usr/ports')
> rescue Errno::EEXISTS
> end
> etc...
> 
> gets tedious.

Don't repeat, wrap in a function. Or make a loop.

def ensureDirExists(name)
   Dir.mkdir(name)
rescue Errno::EEXISTS
end

for dir in ['/usr', '/usr/ports', '/usr/ports/databases',
  '/usr/ports/databases/postgresql-devel']
   ensureDirExists(dir)
end

(Why Ruby insists on all functions to be put in a class?)

> hack scripts that system admins use/write, it's pretty nice to be able
> to just disregard a specific exception.

Code could break horribly if instructions after raise were executed
at all. It would surprise me if raise didn't raise.

case something
when foo; x=1
when bar; x=2
else raise SomeError # x is not initialized here,
                     # it makes no sense to continue
end

-- 
  __("<      Marcin Kowalczyk
  \__/     qrczak / knm.org.pl
   ^^    http://qrnik.knm.org.pl/~qrczak/