Why does this code work with
import qualified Control.OldException as E
but not with
import qualified Control.Exception as E
Here is the code:
fileContents <- (readFile "shpm.txt") `E.catch` (\_ -> return "")
Here is the error I get with the “new” Exception
Ambiguous type variable `e0' in the constraint:
(E.Exception e0) arising from a use of `E.catch'
Probable fix: add a type signature that fixes these type variable(s)
In a stmt of a 'do' block:
fileContents <- (readFile "shpm.txt")
`E.catch` (\ _ -> return "No Tasks")
Because the types have changed. Specifically:
catch :: IO a -> (Exception -> IO a) -> IO acatch :: Exception e => IO a -> (e -> IO a) -> IO aThe new model needs to know what the value of
eis for theException etype. What this means practically is that you need to tell the compiler which exception you are catching. Your example withOldExceptioncatches everything, which is now discouraged (see Catching All Exceptions for more info).A simple fix to your function would be something like this:
Or the lambda-less version: