This question already has an answer here:
I am reading input from the keyboard. The input is supposed to match one of the elements defined in an enumeration type. Here is an example of the enum type:
type NameType is (Bob, Jamie, Steve);
If I receive an input that is not one of these 3, ada raises an IO exception. How do I handle this to where I can simply display a "try again" message and not have the program stop? THANKS
You might try an unchecked conversion to get the value into a variable of NameType then call 'valid on that variable.
Edit to include the example from ADAIC
Create an instance of
Enumeration_IO
forName_Type
, sayName_IO
. In aloop
, enter a nested block to handle anyData_Error
that arises. WhenName_IO.Get
succeeds,exit
theloop
.