On Tue, 3 Dec 2002 22:49:59 +0900, "Shannon Fang" <xrfang / hotmail.com>
wrote:

>Hi,
>
>Can anybody help me on the rescue clause? I tried to catch file not found 
>error of file.open method, but I don't know what type of error to use in 
>rescue clause. i tried to write nothing after rescue, it seems not catching 
>the error. Further more:

Shannon, each rescue needs  the name of one or more Exception classes
to catch.  I used irb to find out what exception File.open raises for
file not found:

	irb(main):001:0> File.open("xxx.yyy")	
	Errno::ENOENT: No such file or directory - "xxx.yyy"
		from (irb):1:in 'open'
		from (irb):1

Looks like Errno::ENOENT is the exception, so this works:

begin
   File.open("xxx.yyy")
rescue Errno::ENOENT
   puts "caught"
end

>
>1. where can I find a reference to different kind of runtime errors? It 
>seems that there are no information on that (Exception Class?) in pickaxe...

IIRC (I don't have my copy of Pickaxe beside me) there are two lists
of exceptions in the Pickaxe, one in the "Exceptions, Catch, and
Throw" chapter and one in the description of the Exception class in
the "Standard Library" chapter. I don't see them in my online copy so
it may be that those lists are actually illustrations, which don't
appear in the online version.

>
>2. in "rescue SyntaxError, NameError => boom", is => used to denote a hash? 
>if so, why NameError is a hash? If not, maybe gavin can add this usage of => 
>to the FunnySymbolsInCode FAQ...
>
>Thanks,
>Shannon
>
>
>
>
>
>_________________________________________________________________
>Tired of spam? Get advanced junk mail protection with MSN 8. 
>http://join.msn.com/?page=features/junkmail
>