I'm building an application services layer, and one of my methods accepts an entity's ID (integer) and returns the referenced entity. Although it seems like it should be simple, looking through the plethora of .NET exceptions, I'm not completely sure what exception I should throw if an entity with the given ID is not found (I don't want to just return null).
There is ObjectNotFoundException, but that is in the System.Data
namespace which means it should be ASP.NET-specific, which this isn't. There is NullReferenceException, but it's recommended that programmers not throw that as it is "internal", and I'm not sure whether it's quite right in this scenario anyway. I don't want to throw the generic Exception. So, what specific exception class would make the most sense to throw here? As this is an app services layer method (thus quite abstract), would it be a good idea for me to limit myself to exceptions in the System.SystemException namespace and/or custom exceptions?