Ok, guys, super easy question (it seems weird that Google didn’t help me with this one):
import IO
--.... yadda, yadda, yadda
file <- openFile "/some/path" ReadMode
How do I check if the handle that I got from openFile is a valid handle, i.e. that the file exists and was opened successfully?
If the file doesn’t exist, or some other error occurs, the call to
openFilewill fail with an exception.For example:
Fails with:
The types of exception that may be thrown by
openFileare listed here, and include:You can catch these errors using Control.Exception, like so: