Re: Question concerning ruby file access



From: Stefan Salewski [mailto:mail@xxxxxxxxxxxx]
# Or in other words: I want to print a text like "File
# with filename "testfile" does not exist" when opening failed.

i usually think it like db's logical unit of work or transaction. i just wrap it w ruby's begin/end and a rescue check as mentioned by sebastian.

something like eg

begin
* File.open("test.rbx") do |f|
* end
rescue =>e
p e.message
end
"No such file or directory - test.rbx"
=> nil

note, you can have more rescues and finetune them. you can also make your own exceptions.. just continue reading on the pickaxe..