Hi
Well, I am saving db properties in a YAML file in a ruby
application (not Rails) and was wondering if an exception is raised if
the file specified is not found. If so which is error. I want to handle
the uncertainty in the availability of the file with rescue.
Thanks
Venkat
Actually let me improve my question. This is the erro I get
C:/Ruby/lib/ruby/1.8/yaml.rb:143:in initialize': No such file or directory - file2.yaml (Errno::ENOENT) from C:/Ruby/lib/ruby/1.8/yaml.rb:143:in
open’
from C:/Ruby/lib/ruby/1.8/yaml.rb:143:in `load_file’
from yaml_prac.rb:3
doesn’t make any sense.
Thanks
Venkat
Errno::ENOENT is a system error, which means “No such file or
directory.”
These values are Constants defined in Errno, so you can see the possible
values via Errno.constansts.
With that piece of information, the error that you get means that in
yaml.rb, on line 143, you were trying to open the file “file2.yaml”
which
did not exist, probably because it is not in the current working
directory,
but maybe because you didn’t ever create it, or because you named it
“FILE2.YAML” and you have a case-sensitive file system.
Ray
On Sat, Jul 25, 2009 at 12:19 AM, Venkat A. <
Thanks for the reply Ray
I purposefully did not create the file to see what error will
be raised. I am sorry I failed to mention that. I am trying to ensure
that this error will not be thrown to the user when a file is not found.
Hence I want to handle it with rescue. How can I achieve this.
Thanks
Venkat
The usual way,
begin
?> File.open(“fjaskfajs”) # Or, whatever code you have on line 3 of
yaml_prac.rb
rescue Errno::ENOENT
p “file not found”
end
“file not found”
=> nil
Ray
On Sat, Jul 25, 2009 at 10:37 AM, Venkat A. <