This answer is based on the assumption that myType
is declared as something like
subtype myType is Character range '1' .. '3';
You can write the output into an unconstraint Character
variable, then check it:
PROCEDURE ask (variable : OUT myType) IS
Input : Character;
BEGIN
Put ("Enter : ");
Get (Input);
Skip_Line;
CASE Input IS
WHEN 'm' =>
RAISE gotM;
WHEN OTHERS =>
-- this will raise Constraint_Error if the value is not
-- in range '1' .. '3'
variable := Input;
END CASE;
EXCEPTION
WHEN OTHERS => RAISE wrongInput;
END ask;
I used case
instead of a simple if
because it sounds like there may be other input values added in the future. Now while this is technically possible, I consider it bad style, because it uses the exception gotM
for implementing non-exceptional behavior. You should re-think your code layout so that you don't have a procedure ask
that can only return '1' .. '3'
but needs to handle other input, too.