Thanks. it&#39;s convenient. <br><br><div class="gmail_quote">2011/1/25 Michael Snoyman <span dir="ltr">&lt;<a href="mailto:michael@snoyman.com">michael@snoyman.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

2011/1/25 Антон Чешков &lt;<a href="mailto:acheshkov@gmail.com">acheshkov@gmail.com</a>&gt;:<br>
<div class="im">&gt; Hello Michael. Please explain how to handle exceptions in Yesod<br>
&gt; applications.<br>
&gt; For example i would to catch the error generated by unique constraint on<br>
&gt; table.<br>
&gt; runDB $ insert $ Table field1 field2<br>
<br>
</div>In general, starting with Persistent 0.4, you will want to use the<br>
monad-peel package[1], which provides facilities for exception<br>
catching in wrapped monads. In Persistent 0.3, you can use the<br>
MonadInvertIO functions available in the neither package[2].<br>
MonadInvertIO and MonadPeelIO are very similar in concept, but<br>
MonadPeelIO is just better[3].<br>
<br>
But in your particular case, you don&#39;t need to resort to runtime<br>
exceptions: just use insertBy[4] or checkUnique[5].<br>
<br>
Michael<br>
<br>
[1] <a href="http://hackage.haskell.org/package/monad-peel" target="_blank">http://hackage.haskell.org/package/monad-peel</a><br>
[2] <a href="http://hackage.haskell.org/packages/archive/neither/0.1.0/doc/html/Control-Monad-Invert.html" target="_blank">http://hackage.haskell.org/packages/archive/neither/0.1.0/doc/html/Control-Monad-Invert.html</a><br>


[3] I wrote MoandInvertIO, Anders Kaseorg wrote MonadPeelIO, and he&#39;s<br>
smarter than me.<br>
[4] <a href="http://hackage.haskell.org/packages/archive/persistent/0.3.1.3/doc/html/Database-Persist.html#v:insertBy" target="_blank">http://hackage.haskell.org/packages/archive/persistent/0.3.1.3/doc/html/Database-Persist.html#v:insertBy</a><br>


[5] <a href="http://hackage.haskell.org/packages/archive/persistent/0.3.1.3/doc/html/Database-Persist.html#v:checkUnique" target="_blank">http://hackage.haskell.org/packages/archive/persistent/0.3.1.3/doc/html/Database-Persist.html#v:checkUnique</a><br>


</blockquote></div><br><br clear="all"><br>-- <br>Best regards,<br>Cheshkov Anton <br>Phone: +7 909 005 18 82<br>Phone: +7 931 511 47 37<br>Skype: cheshkov_anton<br>