1. with Ada.Exceptions;       use Ada.Exceptions; 
  2. with Ada.Task_Termination; use Ada.Task_Termination; 
  3. with Ada.Text_IO;          use Ada.Text_IO; 
  4.  
  5. package body Scoped_Tasks_Finalizer is 
  6.  
  7.    protected body Finalizer is 
  8.  
  9.       procedure Last_Wish (Cause : Cause_Of_Termination; 
  10.                            Id    : Task_Id; 
  11.                            X     : Exception_Occurrence) is 
  12.  
  13.       begin 
  14.          case Cause is 
  15.             when Normal              => Put_Line ("Task " & Image (Id) & " came to a peaceful end."); 
  16.             when Abnormal            => Put_Line ("Somethings really nasty happend to task " & Image (Id)); 
  17.             when Unhandled_Exception => Put_Line ("Unhandled exception " & Exception_Name (X) & " in task " & Image (Id)); 
  18.          end case; 
  19.       end Last_Wish; 
  20.  
  21.       procedure Register (Id : Task_Id) is 
  22.  
  23.       begin 
  24.          Set_Specific_Handler (T => Id, Handler => Last_Wish'Access); 
  25.       end Register; 
  26.  
  27.    end Finalizer; 
  28.  
  29. end Scoped_Tasks_Finalizer;