Impredicative
Impredicative

Reputation: 5069

Haskell: catching low level IO exceptions

According to the System.Directory haddock, renameFile may fail with a number of reasons:

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?

Upvotes: 5

Views: 466

Answers (1)

Yuras
Yuras

Reputation: 13876

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

Upvotes: 5

Related Questions