From: matz@... (Yukihiro Matsumoto) Date: 2001-08-08T07:39:58+09:00 Subject: [ruby-talk:19315] Re: how to "die" in Ruby Hi, In message "[ruby-talk:19310] how to "die" in Ruby" on 01/08/08, markus jais writes: | |hi, |in Perl I can write |open(FH, "/root/.bashrc") or die "error opening file: $!"; |is there another way in Ruby how to do this. |I must say, that I like the ruby way with the exceptions, |I was just curious if there is another (maybe shorter) way |to do this. The shortest way is f = open("/root/.bashrc") # prints: # foo.rb:1:in `open': No such file or directory - "/root/.bashrc" (Errno::ENOENT) If you want to raise an exception with arbitrary message, begin f = open("/root2/.bashrc") rescue raise "error opening file: #{$!}" end or alternatively f = open("/root/.bashrc") rescue raise "error opening file: #{$!}" If you want to exit directly, begin f = open("/root2/.bashrc") rescue puts $! exit 1 end TMTOWTDI matz.