From: Eero Saynatkari Date: 2006-09-01T12:15:16+09:00 Subject: Re: Rescuing a 'require' Garance A Drosehn wrote: > I wanted to use Socket.gethostname to get the current hostname > without executing a unix command. So: > > require 'socket' > $this_host = Socket.gethostname > > I have to run this code on several platforms, and it turned out that > some of them do not have 'socket'. So, my first idea was change > it to: > > begin > require 'socket' > $this_host = Socket.gethostname > rescue rescue LoadError > > $this_host = `hostname`.chomp > end > > but the require still caused the script to terminate on the platforms > which didn't have 'socket'. I already have an alternate solution for > this specific case, but I'm wondering if there was something that I > missed. Is there any way to catch errors from a require command? You need to give the exception class; rescue by itself only catches subclasses of StandardError. -- Posted via http://www.ruby-forum.com/.