C# Throw Exception on use Assert? -


i have system employeeid must alway exist unless there underlying problem.

the way see it, have 2 choices check code:

1:

public void getemployee(employee employee)   {      bool exists = employeerepository.verifyidexists(employee.id);      if (!exists)       {         throw new exception("id not exist");      }   }     

or 2:

public void getemployee(employee employee)   {     employeerepository.assertifnotfound(employee.id);   }   

is option #2 acceptable in c# language?

i because it's tidy in don't looking @ "throw new exception("bla bla bla") type messages outsite class scope.

as rule, should throw exceptions in exceptional circumstances. since 1 such circumstance, throwing exception right thing do.


Comments

Popular posts from this blog

javascript - Enclosure Memory Copies -

php - Replacing tags in braces, even nested tags, with regex -