I have a system where the employeeId must alway exist unless there is some underlying problem.
The way I see it, is that I have two choices to check this code:
1:
public void GetEmployee(Employee employee)
{
bool exists = EmployeeRepository.VerifyIdExists(Employee.Id);
if (!exists)
{
throw new Exception("Id does not exist);
}
}
or 2:
public void GetEmployee(Employee employee)
{
EmployeeRepository.AssertIfNotFound(Employee.Id);
}
Is option #2 acceptable in the C# language?
I like it because it's tidy in that i don't like looking at "throw new Exception("bla bla bla") type messages outsite the class scope.