Is an exception (Error) raised while using YAML.load_file()

V

Venkat Akkineni

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
 
V

Venkat Akkineni

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
 
R

Ray Baxter

[Note: parts of this message were removed to make it a legal post.]

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 Akkineni <
 
V

Venkat Akkineni

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
 
R

Ray Baxter

[Note: parts of this message were removed to make it a legal post.]

The usual way,?> File.open("fjaskfajs") # Or, whatever code you have on line 3 of
yaml_prac.rb"file not found"
=> nil

Ray

On Sat, Jul 25, 2009 at 10:37 AM, Venkat Akkineni <
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,170
Messages
2,570,925
Members
47,464
Latest member
Bobbylenly

Latest Threads

Top