Haskell: catching low level IO exceptions
exception, haskell, io
Solution
`UnsupportedOperation` is ghc-specific. So you have to import `GHC.IO.Exception`, it contains everything you need to check exception type.
Here is an example:
import Control.Exception
import GHC.IO.Exception
main :: IO ()
main = do
action `catch` (\(IOError _ UnsupportedOperation _ _ _ _) -> print "UnsupportedOperation")
where
action = throw $ IOError Nothing UnsupportedOperation "loc" "desc" Nothing Nothing
Problem
According to the System.Directory haddock, `renameFile` may fail with a number of reasons: - HardwareFault A physical I/O error has occurred. [EIO] - InvalidArgument Either operand is not a valid file name. [ENAMETOOLONG, ELOOP] - isDoesNotExistError / NoSuchThing The original file does not exist, or there is no path to the target. [ENOENT, ENOTDIR] - isPermissionError / PermissionDenied The process has insufficient privileges to perform the operation. [EROFS, EACCES, EPERM] - ResourceExhausted Insufficient resources are available to perform the operation. [EDQUOT, ENOSPC, ENOMEM, EMLINK] - UnsatisfiedConstraints Implementation-dependent constraints are not satisfied. [EBUSY] - UnsupportedOperation The implementation does not support renaming in this situation. [EXDEV] - InappropriateType Either path refers to an existing directory. [ENOTDIR, EISDIR, EINVAL, EEXIST, ENOTEMPTY] A couple of these (isPermissionError, isDoesNotExistError) have testing functions, but others (including UnsupportedOperation, in which I'm interested) don't seem to correspond to anything. What is `UnsupportedOperation` and how can I test for it? More generally, how should I go about finding out what something like this is. I can't see anywhere in the source code where it's raised, so I'm guessing it's a wrapper around a lower level error - but how should I deal with those?