[web-devel] Exception Handling on GHandler monad level

Michael Snoyman michael at snoyman.com
Tue May 17 14:16:16 CEST 2011


You want to use liftIOHandler[1]. You should be able to just do:

    function = liftIOHandler $ do ...

However, given that you want to call runDB, which *already* has a call to
liftIOHandler, I'd recommend you take the code from runDB and modify it.

Michael

[1]
http://hackage.haskell.org/packages/archive/yesod-core/0.8.1/doc/html/Yesod-Handler.html#v:liftIOHandler

On Tue, May 17, 2011 at 3:04 PM, Anton Cheshkov <acheshkov at gmail.com> wrote:

> Hi Michael,
>
> i need to handle exception on GHandler monad level.
>
> We have:
>
> *type GHandler sub master = GGHandler<http://hackage.haskell.org/packages/archive/yesod-core/0.8.1/doc/html/Yesod-Handler.html#t:GGHandler> sub
> master (Iteratee<http://hackage.haskell.org/packages/archive/enumerator/0.4.10/doc/html/Data-Enumerator.html#t:Iteratee>
>  ByteString<http://hackage.haskell.org/packages/archive/bytestring/0.9.1.10/doc/html/Data-ByteString.html#t:ByteString>
>  IO<http://hackage.haskell.org/packages/archive/base/4.3.1.0/doc/html/System-IO.html#t:IO>
> **)*
> *
> *data GGHandler sub master m a
>      ...
>             MonadControlIO<http://hackage.haskell.org/packages/archive/monad-control/0.2.0.1/doc/html/Control-Monad-IO-Control.html#t:MonadControlIO> m
> => MonadControlIO<http://hackage.haskell.org/packages/archive/monad-control/0.2.0.1/doc/html/Control-Monad-IO-Control.html#t:MonadControlIO>
>  (GGHandler<http://hackage.haskell.org/packages/archive/yesod-core/0.8.1/doc/html/Yesod-Handler.html#t:GGHandler> sub
> master m)
>
>
> *(Iteratee<http://hackage.haskell.org/packages/archive/enumerator/0.4.10/doc/html/Data-Enumerator.html#t:Iteratee>
>  ByteString<http://hackage.haskell.org/packages/archive/bytestring/0.9.1.10/doc/html/Data-ByteString.html#t:ByteString>
>  IO<http://hackage.haskell.org/packages/archive/base/4.3.1.0/doc/html/System-IO.html#t:IO>
> **) have no instance of * MonadControlIO<http://hackage.haskell.org/packages/archive/monad-control/0.2.0.1/doc/html/Control-Monad-IO-Control.html#t:MonadControlIO> thus
> we got error:
>
> No instance for (MonadControlIO
>                        (Data.Enumerator.Iteratee
> Data.ByteString.Internal.ByteString IO))
>       arising from a use of `E.catch'
>     Possible fix:
>       add an instance declaration for
>       (MonadControlIO
>          (Data.Enumerator.Iteratee Data.ByteString.Internal.ByteString IO))
>
>
> i need something like:
> *
> *
> *function :: Handler (Maybe Int)*
> *function = do *
> *            res <- E.catch (runDB $ do *
> *                            action1*
> *                            action2*
> *                            ... *
> *                            return 1*
> *                   )*
> *                   (\(e :: E.SomeException) -> return 0)*
>
>
> How i can get this ?
>
> Thanks.
>
> --
> Best regards,
> Cheshkov Anton
> Phone: +7 909 005 18 82
> Skype: cheshkov_anton
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/web-devel/attachments/20110517/55f4332d/attachment-0001.htm>


More information about the web-devel mailing list