Yurttas/PL/IL/Ada-95/Exceptions/ehand 01.adb

 1--
 2-- Copyright (C) 1998
 3-- All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
 4--
 5-- Permission to use, copy, modify, and distribute this 
 6-- software and its documentation for EDUCATIONAL purposes
 7-- and without fee is hereby granted provided that this 
 8-- copyright notice appears in all copies. 
 9-- 
10-- 
11 
12-- date   : January 1, 1998.
13-- author : Salih Yurttas.
14
15-- purpose : Error handling by exceptions.
16
17-- ehand_01.adb
18
19
20with Text_IO; use Text_IO;
21 
22procedure EHand_01 is
23
24  package Int_IO is new Integer_IO(Integer); use Int_IO;
25 
26  k   : Integer := 256;
27  I_V : Integer;
28 
29  E : exception;
30
31begin
32 
33  for i in 1..4
34  loop
35
36    loop
37
38      begin
39
40        New_line;
41        Put ("--> I_V : ");
42        Get (I_V);
43
44        if I_V<0 or I_V>=16 then
45          raise E;
46        end if;
47
48        k := k/I_V;
49        Put(k);
50        New_line;
51        exit;
52      exception
53        when CONSTRAINT_ERROR => New_Line;
54                                 Put_Line("Try Again..");
55        when E => New_Line;
56                  Put_Line("Try again : 0 < I_V < 16 ");
57                  Skip_line;
58      end;
59
60    end loop;
61
62  end loop;
63 
64end EHand_01;