Missing case
Now I understand that there can be another valid use case.
This is maybe what Shikhar really wanted but failed to express.
Forgive me Shikhar! May be you're not ignoring children; may be you're -- just the opposite -- overly protective if them?
Forgive me, everyone! Silly me!
We all missed yet another important option.
Here is how:
public class AgeLimitException : System.ApplicationException {
internal AgeLimitException(
int actualAge,
string comment) : base(comment) {
this.fActualAge = actualAge;
}
internal AgeLimitException(int actualAge) {
this.fActualAge = actualAge;
}
public int ActualAge { get { return fActualAge; } }
int fActualAge;
}
public string GetAgeString(int age) {
if (age > 60)
return "senior";
else if (age >= 40 && age <= 59)
return "middle aged";
else if (age >= 20 && age <= 39)
return "adult";
else if (age >= 12 && age <= 19)
return "teenaged";
else
throw new AgeLimitException(age,
"Parential consent required");
}
Beyond the jokes: this is another valid use case of not returning in every case: throwing an exception.
Thank you. ;)