1. with Ada.Text_IO;  use Ada.Text_IO; 
  2. with Ada.Calendar; use Ada.Calendar; 
  3. with Exceptions;   use Exceptions; 
  4.  
  5. pragma Elaborate_All (Exceptions); 
  6.  
  7. package body Scoped_Tasks is 
  8.  
  9.    Start_Up_Time       : constant Time     := Clock; 
  10.    No_of_Iterations    : constant Positive := 3; 
  11.    Delay_Per_Iteration : constant Duration := 1.5; 
  12.  
  13.    subtype Repeat_for is Positive range 1 .. No_of_Iterations; 
  14.  
  15.    task body Scoped_Task is 
  16.  
  17.       Id : Colours; 
  18.  
  19.    begin 
  20.       accept Hand_over_Task_Id (Set_Id : Colours) do 
  21.          Id := Set_Id; 
  22.       end Hand_over_Task_Id; 
  23.  
  24.       if Id = Blue then 
  25.          raise Scoped_Task_is_not_too_well; 
  26.       end if; 
  27.  
  28.       for I in Repeat_for loop 
  29.          Put_Line ("Task " & Colours'Image (Id) & " at" & Duration'Image (Clock - Start_Up_Time) & " seconds since start up"); 
  30.          delay Delay_Per_Iteration; 
  31.       end loop; 
  32.  
  33.    exception -- test what happens if you leave these two lines out. 
  34.       when X_Id : others => Show_Exception (X_Id); 
  35.  
  36.    end Scoped_Task; 
  37.  
  38. end Scoped_Tasks;