What kind of exception should I use for “No Record Found” ? (C#)

KeyNotFoundException would be a reasonable choice, and would conform to the Microsoft guideline to:

Consider throwing existing exceptions residing in the System namespaces instead of creating custom exception types.

However you could consider creating your own Exception type if (again from the Microsoft guidelines):

… you have an error condition that can be programmatically handled in a different way than any other existing exceptions.

If you do create your own Exception, you should follow the guidelines for designing custom exceptions, e.g. you should make your Exception type Serializable.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)