Saturday, February 27, 2010

Unified storage level exceptions

With previous versions of DataObjects.Net v4.x there was no way to handle database errors in one fashion. All ADO.NET exceptions (like SqlException for SQL Server or NpgsqlException for PostgreSQL) were passed to user code simply wrapped in StorageException. These times have gone. Upcoming DataObjects.Net v4.2 will support a nice new feature. We called it "unified storage level exceptions". As the name suggests all ADO.NET errors are now unified.

Here are the exceptions you could expect. They are naturally grouped by cause of error.

StorageException is the base exception for all storage errors.

Constraint violations:
  • ConstraintViolationException is the base exception for SQL constraint violations.
  • CheckConstraintViolationException denotes violation of a check or not null constraint.
  • ReferentialContraintViolationException denotes a violation of a foreign key constraint.
  • UniqueConstraintViolationException denotes a violation of a unique or primary key constraint.
Concurrent access errors:
  • ReprocessableException is the base exception for TransactionSerializationFailureException and DeadlockException
  • DeadlockException will surely be used very often, it’s thrown when you got into a deadlock with other transaction working on the same data.
  • TransactionSerializationFailureException denotes any concurrent access problem except deadlock.

General errors:

  • ConnectionErrorException is thrown when there is something wrong with the database connection.
  • SyntaxErrorException is thrown when RDBMS was not satisfied with the supplied SQL query :-)
  • OperationTimeoutException is thrown when server spent too much time executing your query and ADO.NET client decided it can not wait any longer :-) This exception probably denotes a live lock.

There are other descendants of StorageException but they are not related with database communication and are not shown here.

No comments:

Post a Comment