Which .NET exception to throw for invalid database state?
Posted
by jslatts
on Stack Overflow
See other posts from Stack Overflow
or by jslatts
Published on 2010-04-13T16:44:28Z
Indexed on
2010/04/13
16:53 UTC
Read the original article
Hit count: 212
I am writing some data access code and I want to check for potentially "invalid" data states in the database. For instance, I am returning a widget out of the database and I only expect one. If I get two, I want to throw an exception. Even though referential integrity should prevent this from occurring, I do not want to depend on the DBAs never changing the schema.
I would like to use the System.IO.InvalidDataException, except that I am not dealing with a file stream so it would be misleading. I ended up going with a generic applicationexception. Anyone have a better idea?
© Stack Overflow or respective owner