I'm trying handling an exception when I read a file but I'm receiving the message
parse error on input `if'
readTxt = do
{catch (read_file) fix_error;}
where
read_file = do
{
f <- openFile "file.txt" ReadMode;
content <- hGetContents f;
putStrLn content;
hClose f;
}
fix_error erro if = isDoesNotExistError erro
then do
{
putStr "Exception: file doesn't exists";
writeFile "file.txt" "First Line"
}
else ioError erro
I read that when I have an if
I need that the then
and else
clauses return the same type. I believe that I'm doing this, so I don't know why I'm receiving the error message