The following code sequence often appears (at least in my code)

switch( patient.Gender )

{

case Gender.Male:

break;

case Gender.Female:

break;

case Gender.Unspecified:

break;

default:

throw new Exception (“Invalid Gender value”);

}

The throw statement should create an exception with a category. In that case, the exception could mean the patient data is invalid in the database or that somewhere is an error in the code. In the first case, the exception should be InvalidData, in the second case

it should be CodingError (if the exception protects the code from a coding error, an alternative mean of signaling it would be to use Debug.Assert, but the assertions do not make it to production code and also they may be hard to trace by the support people).

Advertisements