The above showed how to use optional value. This below shows how to check and what to do if an optional value was not what is expected. This is done by explicitly checking, after reading the optional value, that its value is one that is expected. Like this
Clear["Global`*"]; Options[processPerson]={"sex"->"male"}; processPerson::msg="`1`"; processPerson[name_String,age_?NumericQ,opt:OptionsPattern[{processPerson}]]/;age>0:=Module[{sex}, sex = OptionValue["sex"]; If[Not[MemberQ[{"male","female"},sex]], Message[processPerson::msg,"Invalid value for sex found. "<>sex<>" but expected one of {\"male\", \"female\"}"]; Abort[] ]; Print["Name = ",name]; Print["age = ",age]; Print["sex = ",sexOfPerson] ]
Now we are ready to call the function. Lets call it with bad value for the optional parameter
processPerson["me",10,"sex"->"car"] processPerson::msg: Invalid value for sex found. car but expected one of {"male", "female"} $Aborted