Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not in scope: `catch'

Tags:

scope

haskell

I am reading learn you a haskell for great good but i faced an error of Not in scope: `catch' when I read the exception section in input & output chapter

here is my code:

import System.Environment  
import System.IO  
import System.IO.Error  

main = toTry `catch` handler  

toTry :: IO ()  
toTry = do (fileName:_) <- getArgs  
           contents <- readFile fileName  
           putStrLn $ "The file has " ++ show (length (lines contents)) ++ " lines!"  

handler :: IOError -> IO ()  
handler e = putStrLn "Whoops, had some trouble!"  

and I get this error message:

Not in scope: `catch'
like image 438
bling5630 Avatar asked Mar 05 '17 14:03

bling5630


Video Answer


1 Answers

catch is exported by the Control.Exception module.

import Control.Exception
like image 70
Thomas M. DuBuisson Avatar answered Sep 22 '22 05:09

Thomas M. DuBuisson