
2011/1/25 Антон Чешков
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-M... [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/Data... [5] http://hackage.haskell.org/packages/archive/persistent/0.3.1.3/doc/html/Data...