Yurttas/PL/IL/Ada-95/F/02/03/00/error handling 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-- error_handling_01.adb
18
19
20with Text_IO; use Text_IO;
21 
22procedure Error_Handling_01 is
23
24  package Int_IO is new Integer_IO(Integer); use Int_IO;
25 
26  N : Integer := 4;
27
28  D : Integer := 256;
29
30  Value : Integer;
31 
32  E : exception;
33
34begin
35 
36  for I in 1..N
37  loop
38
39    loop
40
41      begin
42
43        New_line;
44
45        Put("--> Value : ");
46        Get(Value);
47
48        if Value<0 or Value>=16 then
49          raise E;
50        end if;
51
52        D := D/Value;
53
54        Put(D);
55        New_line;
56
57        exit;
58      exception
59        when CONSTRAINT_ERROR => New_Line;
60                                 Put_Line("Try Again...");
61        when E => New_Line;
62                  Put_Line("Try again : 0 < Value < 16 ");
63                  Skip_line;
64      end;
65
66    end loop;
67
68  end loop;
69 
70end Error_Handling_01;