E
Eric the half a Bee
Hello
I am trying to implement a search function within a collection of
Employees. I am searching for a specific EmpID number in the collection,
and if it is found, I want to return the Employee. This I can do.
The problem comes if the EmpID is not found in the collection. The only way
to achieve this I can think of is to throw an invalid argument exception:
public Employee WithID(int EmpID)
{
try
{
foreach(Employee employee in personnel)
{
if (employee.EmpID == employee.EmpID)
return employee;
}
throw new ArgumentException();
}
catch (ArgumentException ae)
{
Console.Out.WriteLine("Invalid argument passed. EmpID not in
records.{0}",ae.ToString());
Console.Out.WriteLine(ae);
}
finally
{
return new Manager();
}
}
This of course doesn't work either, as control apparently cannot leave a
finally clause.
Any suggestions?
Thanks
I am trying to implement a search function within a collection of
Employees. I am searching for a specific EmpID number in the collection,
and if it is found, I want to return the Employee. This I can do.
The problem comes if the EmpID is not found in the collection. The only way
to achieve this I can think of is to throw an invalid argument exception:
public Employee WithID(int EmpID)
{
try
{
foreach(Employee employee in personnel)
{
if (employee.EmpID == employee.EmpID)
return employee;
}
throw new ArgumentException();
}
catch (ArgumentException ae)
{
Console.Out.WriteLine("Invalid argument passed. EmpID not in
records.{0}",ae.ToString());
Console.Out.WriteLine(ae);
}
finally
{
return new Manager();
}
}
This of course doesn't work either, as control apparently cannot leave a
finally clause.
Any suggestions?
Thanks