Issues with new Control.Exception

David Menendez dave at zednenem.com
Wed Jan 28 16:50:09 EST 2009


On Wed, Jan 28, 2009 at 4:00 PM, John Goerzen <jgoerzen at complete.org> wrote:
>  * Catch doesn't work in many common cases anymore.  In particular,
>   the example right there in haddock is broken:
>
>      catch (openFile f ReadMode)
>       (\e -> hPutStr stderr ("Couldn't open "++f++": " ++ show e))
>
>   That's broken, of course, because the type of e isn't fixed.
>   But it's also broken because openFile has a different return type
>   than hPutStr.

I think the correct code would be something like this:

    catch (openFile f ReadMode)
        (\(e::SomeException) ->
            hPutStr stderr ("Couldn't open "++f++": " ++ show e)) >>
            throwIO e)

Although it might be better to replace "SomeException" with "IOException".

-- 
Dave Menendez <dave at zednenem.com>
<http://www.eyrie.org/~zednenem/>


More information about the Libraries mailing list