on dev help sign in
catch and handle exceptions
d276200Eitan Chatav
squeal-postgresql/src/Squeal/PostgreSQL/PQ.hs+19−1
@@ -50,7 +50,7 @@ module Squeal.PostgreSQL.PQ
50 , MonadPQ (..)
50 , MonadPQ (..)
51 , PQRun
51 , PQRun
52 , pqliftWith
52 , pqliftWith
53− -- * Result
53+ -- * Results
54 , LibPQ.Result
54 , LibPQ.Result
55 , LibPQ.Row
55 , LibPQ.Row
56 , ntuples
56 , ntuples
@@ -63,7 +63,10 @@ module Squeal.PostgreSQL.PQ
63 , resultStatus
63 , resultStatus
64 , resultErrorMessage
64 , resultErrorMessage
65 , resultErrorCode
65 , resultErrorCode
66+ -- * Exceptions
66 , SquealException (..)
67 , SquealException (..)
68+ , catchSqueal
69+ , handleSqueal
67 ) where
70 ) where
68
71
69import Control.Exception.Lifted
72import Control.Exception.Lifted
@@ -651,3 +654,18 @@ tryResult result = liftBase $ do
651 stateCode <- LibPQ.resultErrorField result LibPQ.DiagSqlstate
654 stateCode <- LibPQ.resultErrorField result LibPQ.DiagSqlstate
652 msg <- LibPQ.resultErrorMessage result
655 msg <- LibPQ.resultErrorMessage result
653 throw $ PQException status stateCode msg
656 throw $ PQException status stateCode msg
657+
658+-- | Catch `SquealException`s.
659+catchSqueal
660+ :: MonadBaseControl IO io
661+ => io a
662+ -> (SquealException -> io a) -- ^ handler
663+ -> io a
664+catchSqueal = catch
665+
666+-- | Handle `SquealExceptions`s.
667+handleSqueal
668+ :: MonadBaseControl IO io
669+ => (SquealException -> io a) -- ^ handler
670+ -> io a -> io a
671+handleSqueal = handle