2017-03-05 71 views
1

我读书学习你极大的利好一个Haskell,但我在范围内面临的并不是一个错误:'抓”,当我在输入&输出章节阅读异常部分不在范围内:'抓“

这里我的代码:

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!" 

,我得到这个错误信息:

Not in scope: `catch' 
+4

注意:您可以随时使用hoogle搜索类似的东西http://hoogle.haskell.org/?hoogle=catch – epsilonhalbe

+2

曾经是在'Prelude'这大概产生是因为'catch'。 – Michael

回答

12

catchControl.Exception模块导出。

import Control.Exception