From: Brian Candler Date: 2010-04-19T17:31:24+09:00 Subject: Re: iconv transfer code botp wrote: >> So if you want to write programs which don't crash, the first is >> arguably better. > > we disagree there but what do you mean by "crash"? I mean "raise an exception". The first example I wrote will never raise an exception. The second can. Code to demonstrate: str = "\xff" File.open("out1","w") { |f| f.puts str } File.open("out2","w:UTF-8") { |f| f.puts str } Line 2 will never raise an exception, regardless of the content or the encoding of str, and regardless of environment variable settings. It just writes the string to the file. Line 3 may raise an exception. It does in this particular program because str has data tagged as ASCII-8BIT which cannot be transcoded to UTF-8. -- Posted via http://www.ruby-forum.com/.