Ruby 2.4

IOError

IOError类

Parent:StandardError

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 + s,这些不是IOError的子类:

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