Reputation: 15434
I am trying to cach exception caused by read function:
run :: CurrentData -> IO ()
run current = do
{
x <- (getCommandFromUser) `E.catch` handler;
updated <- executeCommand x current;
run updated;
} where handler :: E.IOException -> IO Command
handler e = do putStrLn "wrong command format" >> return (DoNothing);
In this code function getCommandfrom user gets some string from user and then tries to read some data from this string using "read" function
If read fails there is exception thrown:
*** Exception : prelude.read : no parse
and program exits... I can't catch this exception - what is type of this exception???
I tried also E.SomeException instead of E.IOException...
E is from import Control.Exception As E
Upvotes: 2
Views: 573
Reputation: 183898
"what is type of this exception?" The type is ErrorCall
, also available from Control.Exception
. An ErrorCall
is what is thrown when the error
function is called.
Just change the type of handler
and it will work. A last resort to get things working is to catch E.SomeException
, but that's almost always the wrong thing to do.
Upvotes: 1