@@ -1,6 +1,8 @@
1{-# LANGUAGE CPP, BangPatterns, DoAndIfThenElse, RecordWildCards #-}
1{-# LANGUAGE CPP, BangPatterns, DoAndIfThenElse, RecordWildCards #-}
2{-# LANGUAGE DeriveDataTypeable, DeriveGeneric #-}
2{-# LANGUAGE DeriveDataTypeable, DeriveGeneric #-}
3{-# LANGUAGE GeneralizedNewtypeDeriving #-}
3{-# LANGUAGE GeneralizedNewtypeDeriving #-}
4+{-# LANGUAGE ExistentialQuantification #-}
5+{-# LANGUAGE InstanceSigs #-}
5------------------------------------------------------------------------------
7------------------------------------------------------------------------------
@@ -81,6 +83,25 @@ data Connection = Connection {
81instance Eq Connection where
83instance Eq Connection where
82 x == y = connectionHandle x == connectionHandle y
84 x == y = connectionHandle x == connectionHandle y
86+-- | Superclass for postgresql exceptions
87+data SomePostgreSqlException = forall e. Exception e => SomePostgreSqlException e
90+postgresqlExceptionToException :: Exception e => e -> SomeException
91+postgresqlExceptionToException = toException . SomePostgreSqlException
93+postgresqlExceptionFromException :: Exception e => SomeException -> Maybe e
94+postgresqlExceptionFromException x = do
95+ SomePostgreSqlException a <- fromException x
98+instance Show SomePostgreSqlException where
99+ showsPrec :: Int -> SomePostgreSqlException -> ShowS
100+ showsPrec p (SomePostgreSqlException e) = showsPrec p e
102+instance Exception SomePostgreSqlException where
103+ displayException (SomePostgreSqlException e) = displayException e
84data SqlError = SqlError {
105data SqlError = SqlError {
85 sqlState :: ByteString
106 sqlState :: ByteString
86 , sqlExecStatus :: ExecStatus
107 , sqlExecStatus :: ExecStatus
@@ -92,7 +113,10 @@ data SqlError = SqlError {
92fatalError :: ByteString -> SqlError
113fatalError :: ByteString -> SqlError
93fatalError msg = SqlError "" FatalError msg "" ""
114fatalError msg = SqlError "" FatalError msg "" ""
95−instance Exception SqlError
116+instance Exception SqlError where
117+ toException = postgresqlExceptionToException
118+ fromException = postgresqlExceptionFromException
97-- | Exception thrown if 'query' is used to perform an @INSERT@-like
121-- | Exception thrown if 'query' is used to perform an @INSERT@-like
98-- operation, or 'execute' is used to perform a @SELECT@-like operation.
122-- operation, or 'execute' is used to perform a @SELECT@-like operation.
@@ -101,7 +125,9 @@ data QueryError = QueryError {
101 , qeQuery :: Query
125 , qeQuery :: Query
102 } deriving (Eq, Show, Typeable)
126 } deriving (Eq, Show, Typeable)
104−instance Exception QueryError
128+instance Exception QueryError where
129+ toException = postgresqlExceptionToException
130+ fromException = postgresqlExceptionFromException
106-- | Exception thrown if a 'Query' could not be formatted correctly.
132-- | Exception thrown if a 'Query' could not be formatted correctly.
107-- This may occur if the number of \'@?@\' characters in the query
133-- This may occur if the number of \'@?@\' characters in the query
@@ -112,7 +138,9 @@ data FormatError = FormatError {
112 , fmtParams :: [ByteString]
138 , fmtParams :: [ByteString]
113 } deriving (Eq, Show, Typeable)
139 } deriving (Eq, Show, Typeable)
115−instance Exception FormatError
141+instance Exception FormatError where
142+ toException = postgresqlExceptionToException
143+ fromException = postgresqlExceptionFromException
117data ConnectInfo = ConnectInfo {
145data ConnectInfo = ConnectInfo {
118 connectHost :: String
146 connectHost :: String