I am looking at input channel functions at OCaml library : In_channel and I do not understand the difference between close_noerr and close:
val close : t -> unit
Close the given channel. Input functions raise a Sys_error exception when they
are applied to a closed input channel, except In_channel.close, which does
nothing when applied to an already closed channel.
val close_noerr : t -> unit
Same as In_channel.close, but ignore all errors.
It says that close_noerr is the same as close “but ignore all errors”, but right above, it says that close does not raise an exception anyway ? So are the two functions identical and kept for history reasons ? What does “ignoring all errors” mean ? Does it mean that it is defined by something like
let close_noerr ic = try close ic with _ -> ()
? But since close does not raise exceptions anyway, the with part seems superfluous…
I don’t think you can read the documentation as saying that close does not raise any exception. Rather, the doc is saying that close does not raise a particular exception in a particular case.
so you think that close may raise other exceptions ?
Like all other I/O functions, close may raise Sys_error _ to report operating system errors (as is mentioned in the comment following the definition of the Sys_error exception). The comment following the declaration of close only means that if you call close on an already-closed channel then no error is raised, but other errors may be raised if the system call fails.
Thanks. I had understood the paragraph you link to as “Sys_error is an exception that may be raised by some I/O functions”, whereas it means “Sys_error is an exception that may be raised by all I/O functions except [the ones I enumerated above]”. Anyway: solution accepted and thanks again!