类 IOError

IO 操作失败时引发。

File.open("/etc/hosts") {|f| f << "example"}
  #=> IOError: not opened for writing

File.open("/etc/hosts") {|f| f.close; f.read }
  #=> IOError: closed stream

请注意,一些 IO 失败会引发 SystemCallError,而这些错误不是 IOError 的子类

File.open("does/not/exist")
  #=> Errno::ENOENT: No such file or directory - does/not/exist