What is the clearest way to open a file and do "rescue" when it cannot be opened in Ruby -
i dealing issue using following code
begin file.open(filename, 'r') rescue print "failed open #{filename}\n" exit end
is there way more perl 'open (in, $filename) || die "failed open $filename\n"'
thanks.
file.open("doesnotexist.txt", 'r')
is enough. if file not exist, raise exception. not caught, program exits.
# =>test6.rb:1:in `initialize': no such file or directory @ rb_sysopen - doesnotexist.txt (errno::enoent)
Comments
Post a Comment