The Ada Program: simple_read.adb

  1 -- simple_read.adb:  subranges, enumeration IO, predefined exception handling
  2 
  3 with Ada.Text_IO;
  4 use Ada;
  5 
  6 procedure Simple_Read is
  7 
  8    type Color_Type is (Red, Green, Yellow, Orange, Purple, Blue);
  9    package Color_IO is new Text_IO.Enumeration_IO (Enum=>Color_Type);
 10    subtype Subcolor is Color_Type range Green .. Orange;
 11    Color: Subcolor;
 12 
 13 begin
 14 
 15    Color_IO.Get (Color);
 16    Color_IO.Put (Color);
 17    Text_IO.New_Line;
 18 
 19 exception
 20 
 21    when Constraint_Error =>
 22       Text_IO.Put_Line ("Color value out of range.");
 23 
 24    when Text_IO.Data_Error =>
 25       Text_IO.Put_Line ("Illegal color typed in.");
 26 
 27    when Text_IO.Device_Error =>
 28       Text_IO.Put_Line ("Hardware error."):
 29 
 30 end Simple_Read;