Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Control.Exception
- getWord :: IO String
- getWord =
- putStrLn "Enter something:" >>
- getLine >>= \name ->
- case name of
- "bad" -> ioError $ userError "bad word detected"
- _ -> return name
- getWordWithoutBadWord :: IO String
- getWordWithoutBadWord = catch getWord handler
- where handler :: IOError -> IO String
- handler e = return $ "(filtered) - reason: " ++ show e
- main :: IO ()
- main = getWordWithoutBadWord >>= \name -> putStrLn name
Add Comment
Please, Sign In to add comment