on dev help sign in
catch and handle exceptions
commitd2762007843714990edfa0828aad4bf7ad63e58f authorEitan Chatav <eitan.chatav@gmail.com> dateWed 5 Sep 2018, 12:34 (8 years ago) parent015d2c1
1 file changed+19−1
squeal-postgresql/src/Squeal/PostgreSQL/PQ.hs+19−1
squeal-postgresql/src/Squeal/PostgreSQL/PQ.hs+19−1
@@ -50,7 +50,7 @@ module Squeal.PostgreSQL.PQ
5050 , MonadPQ (..)
5151 , PQRun
5252 , pqliftWith
53− -- * Result
53+ -- * Results
5454 , LibPQ.Result
5555 , LibPQ.Row
5656 , ntuples
@@ -63,7 +63,10 @@ module Squeal.PostgreSQL.PQ
6363 , resultStatus
6464 , resultErrorMessage
6565 , resultErrorCode
66+ -- * Exceptions
6667 , SquealException (..)
68+ , catchSqueal
69+ , handleSqueal
6770 ) where
6871
6972import Control.Exception.Lifted
@@ -651,3 +654,18 @@ tryResult result = liftBase $ do
651654 stateCode <- LibPQ.resultErrorField result LibPQ.DiagSqlstate
652655 msg <- LibPQ.resultErrorMessage result
653656 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