2017-03-05 70 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