不在范围内:`catch'

bli*_*630 6 haskell scope

我正在阅读为了一个很好的东西,你学习了一个haskell,但是当我读到输入和输出章节中的异常部分时,我遇到了一个不在范围内的错误:`catch'

这是我的代码:

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!"  
Run Code Online (Sandbox Code Playgroud)

我收到此错误消息:

Not in scope: `catch'
Run Code Online (Sandbox Code Playgroud)

Tho*_*son 18

catchControl.Exception模块导出.

import Control.Exception
Run Code Online (Sandbox Code Playgroud)