[Haskell-cafe] Problem with a sample from RWH
C K Kashyap
ckkashyap at gmail.com
Thu Sep 30 02:46:37 EDT 2010
Thanks Ivan,
>
> * Keep using old-style exceptions. With GHC 6.10 and 6.12, import
> Control.OldException instead of Control.Exception
> * Manually migrate the RWH code to new-style exceptions; there are two
> ways of doing this:
> - For production code, you should add explicit type signatures, etc.
> for your exception-handling functions passed to handle, etc.
> - For just playing around, use SomeException: e.g.: handle (\
> SomeException{} -> putStrLn "Text") (print x)
>
Could you please review the change I've done to Don Stewart's
scripting example -
run s = handle (fail . show) $ do
(ih,oh,eh,pid) <- runInteractiveCommand s
so <- hGetContents oh
se <- hGetContents eh
hClose ih
ex <- waitForProcess pid
case ex of
ExitFailure e -> fail $ "Failed with status: " ++ show e
_ | not (null se) -> fail se
| otherwise -> return so
My change -
run s = handle (\e@(SomeException{}) -> return (show e)) $ do
(ih,oh,eh,pid) <- runInteractiveCommand s
so <- hGetContents oh
se <- hGetContents eh
hClose ih
ex <- waitForProcess pid
case ex of
ExitFailure e -> fail $ "Failed with status: " ++ show e
_ | not (null se) -> fail se
| otherwise -> return so
--
Regards,
Kashyap
More information about the Haskell-Cafe
mailing list