[web-devel] Yesod. Handle Exception.
Антон Чешков
acheshkov at gmail.com
Tue Jan 25 19:28:29 CET 2011
Thanks. it's convenient.
2011/1/25 Michael Snoyman <michael at snoyman.com>
> 2011/1/25 Антон Чешков <acheshkov at gmail.com>:
> > Hello Michael. Please explain how to handle exceptions in Yesod
> > applications.
> > For example i would to catch the error generated by unique constraint on
> > table.
> > runDB $ insert $ Table field1 field2
>
> In general, starting with Persistent 0.4, you will want to use the
> monad-peel package[1], which provides facilities for exception
> catching in wrapped monads. In Persistent 0.3, you can use the
> MonadInvertIO functions available in the neither package[2].
> MonadInvertIO and MonadPeelIO are very similar in concept, but
> MonadPeelIO is just better[3].
>
> But in your particular case, you don't need to resort to runtime
> exceptions: just use insertBy[4] or checkUnique[5].
>
> Michael
>
> [1] http://hackage.haskell.org/package/monad-peel
> [2]
> http://hackage.haskell.org/packages/archive/neither/0.1.0/doc/html/Control-Monad-Invert.html
> [3] I wrote MoandInvertIO, Anders Kaseorg wrote MonadPeelIO, and he's
> smarter than me.
> [4]
> http://hackage.haskell.org/packages/archive/persistent/0.3.1.3/doc/html/Database-Persist.html#v:insertBy
> [5]
> http://hackage.haskell.org/packages/archive/persistent/0.3.1.3/doc/html/Database-Persist.html#v:checkUnique
>
--
Best regards,
Cheshkov Anton
Phone: +7 909 005 18 82
Phone: +7 931 511 47 37
Skype: cheshkov_anton
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/web-devel/attachments/20110125/cc1a1c64/attachment-0001.htm>
More information about the web-devel
mailing list