C
cmay
I'm just looking for some other opinions on this.
I have a control that does employee lookups, auto complete of the name
etc.
Let say that this control is:
Company.Controls.Web.LookupControls.EmployeeLookupControl
Now I have a Employee class:
Company.Business.Employee
The employee class takes an employee ID as one of its constructors, so
if you pass it an ID number for an employee that doesn't exist (for
example -1 or 100000000), it throws an exception:
Company.Business.EmployeeNotFoundException
Now my dilema is what to do when my application passes an invalid ID
number to my control EmployeeLookupControl. The lookup control catches
the EmployeeNotFoundException.
One part of me thinks that it should simply rethrown the
EmployeeNotFoundException, and part of me thinks it should thrown it's
OWN exception so that consumers of the LookupControl would only have to
expect exceptions that belong to it, not other DLLs/namespaces. So
then I started thinking, what would I name the new exception if I did
choose to throw an exception? It seems like EmployeeNotFoundException
properly describes the problem, but I am not sure having 2 exceptions
with the same name is a good idea, even if they are in different
namespaces.
So to boil it down.
Option 1: Rethrow the Company.Business.EmployeeNotFoundException
exception. Then applications would have to have a reference to the
DLL that holds that exception class, and developers would have to deal
with exceptions from other DLLs than the one they are dealing with when
setting the ID value of the employee.
Option 2: Make an exception class within the LookupControls DLL and
throw this exception.
Sub Option 2a: Use the same name EmployeeNotFoundException. It's
ok b/c its in a different namespace.
Sub Option 2b: Make up a different name for the exception b/c it's
not good practice to have 2 exceptions with the same name, even if they
are in different namespaces.
I have a control that does employee lookups, auto complete of the name
etc.
Let say that this control is:
Company.Controls.Web.LookupControls.EmployeeLookupControl
Now I have a Employee class:
Company.Business.Employee
The employee class takes an employee ID as one of its constructors, so
if you pass it an ID number for an employee that doesn't exist (for
example -1 or 100000000), it throws an exception:
Company.Business.EmployeeNotFoundException
Now my dilema is what to do when my application passes an invalid ID
number to my control EmployeeLookupControl. The lookup control catches
the EmployeeNotFoundException.
One part of me thinks that it should simply rethrown the
EmployeeNotFoundException, and part of me thinks it should thrown it's
OWN exception so that consumers of the LookupControl would only have to
expect exceptions that belong to it, not other DLLs/namespaces. So
then I started thinking, what would I name the new exception if I did
choose to throw an exception? It seems like EmployeeNotFoundException
properly describes the problem, but I am not sure having 2 exceptions
with the same name is a good idea, even if they are in different
namespaces.
So to boil it down.
Option 1: Rethrow the Company.Business.EmployeeNotFoundException
exception. Then applications would have to have a reference to the
DLL that holds that exception class, and developers would have to deal
with exceptions from other DLLs than the one they are dealing with when
setting the ID value of the employee.
Option 2: Make an exception class within the LookupControls DLL and
throw this exception.
Sub Option 2a: Use the same name EmployeeNotFoundException. It's
ok b/c its in a different namespace.
Sub Option 2b: Make up a different name for the exception b/c it's
not good practice to have 2 exceptions with the same name, even if they
are in different namespaces.