-
Notifications
You must be signed in to change notification settings - Fork 2
exceptions
Alexey Borzov edited this page Feb 17, 2025
·
3 revisions
Warning
These docs are outdated and are no longer maintained. The manual is now on pg-wrapper.readthedocs.io
The package contains base exception interface \sad_spirit\pg_wrapper\Exception and several specialized exception classes that extend SPL Exception classes and implement this interface. Therefore all exceptions thrown in pg_wrapper can be caught with
try {
// Do some database-related stuff
} catch (\sad_spirit\pg_wrapper\Exception $e) {
// Handle exception
}All exception classes belong to sad_spirit\pg_wrapper\exceptions namespace:
-
BadMethodCallException extends \BadMethodCallException- Namespaced version of SPL'sBadMethodCallException -
InvalidArgumentException extends \InvalidArgumentException- Namespaced version of SPL'sInvalidArgumentException. -
OutOfBoundsException extends \OutOfBoundsException- Namespaced version of SPL'sOutOfBoundsException. -
RuntimeException extends \RuntimeException- Namespaced version of SPL's RuntimeException.-
ConnectionException extends RuntimeException- Thrown when database connection fails. -
ServerException extends RuntimeException- Exception thrown when query fails. The class definesgetSqlState()method returning SQLSTATE error code if one is available. It also contains class constants for all such codes so thatServerException::DIVISION_BY_ZEROcan be checked rather than'22012'. Several specialized subclasses ofServerExceptionbelong tosad_spirit\pg_wrapper\exceptions\servernamespace:-
ConstraintViolationException- Thrown when database integrity constraint is violated. It defines an additionalgetConstraintName()method returning name of that constraint if one is available. -
DataException- Thrown when there are problems with processed data, like division by zero or numeric value out of range. -
FeatureNotSupportedException- Thrown when an attempt to use functionality not supported by Postgres is made. -
InsufficientPrivilegeException- Thrown when an action fails due to insufficient permissions. -
InternalErrorException- Thrown when a database encounters some internal error: e.g. transaction state is invalid. -
OperationalException- Thrown for errors related to database's operation that are not necessarily under the control of programmer. -
ProgrammingException- Thrown for programming errors: invalid SQL syntax, undefined or ambiguous objects, etc. -
QueryCanceledException- Thrown when query is canceled, either due to statement_timeout setting or user request. -
TransactionRollbackException- Thrown when transaction is rolled back due to deadlock or serialization failure.
-
-
-
TypeConversionException extends \DomainException- Exception thrown when conversion of value from/to database representation fails.
Generally, if query fails:
-
ConnectionExceptionis thrown when connection to server failed. - Subclass of
ServerExceptionis thrown based onSQLSTATEerror code when said code is available, genericServerExceptionotherwise.