[web-devel] Yesod. Handle Exception.
michael at snoyman.com
Tue Jan 25 19:21:39 CET 2011
2011/1/25 Антон Чешков <acheshkov at gmail.com>:
> Hello Michael. Please explain how to handle exceptions in Yesod
> For example i would to catch the error generated by unique constraint on
> runDB $ insert $ Table field1 field2
In general, starting with Persistent 0.4, you will want to use the
monad-peel package, which provides facilities for exception
catching in wrapped monads. In Persistent 0.3, you can use the
MonadInvertIO functions available in the neither package.
MonadInvertIO and MonadPeelIO are very similar in concept, but
MonadPeelIO is just better.
But in your particular case, you don't need to resort to runtime
exceptions: just use insertBy or checkUnique.
 I wrote MoandInvertIO, Anders Kaseorg wrote MonadPeelIO, and he's
smarter than me.
More information about the web-devel