The following Ada package provides a service. During the provision of this service the exceptions A, B, C and D can be raised.
package Server is
A, B, C, D : exception;
procedure Service; -- can raise $A, B, C$ or $D$
end Server;
In the following procedure two tasks are created; task One rendezvous with task Two. During the rendezvous task, Two calls the Service provided by the server package.
with Server; use Server;
with Ada.Text_Io; use Ada.Text_Io;
procedure Main is
task One;
task Two is
entry Sync;
end Ivo;
task body one is
begin
Two.Sync;
exception
when $A \Rightarrow$
Put_Line("A trapped in one ");
raise;
when $B \Rightarrow$
Put_Line ("B trapped in one");
raise $C$;
when $\mathrm{C}=>$
Put_Line("C trapped in one");
when $\mathrm{D} \Rightarrow$
Put_Line("D trapped in one");
end;
task body Two is
begin -- block $X$
begin -- block $Y$
begin -- block Z
accept Sync do
begin
Service;
exception
when $\mathrm{A}=>$
Put_Line("A trapped in sync");
when $\mathrm{B} \Rightarrow$
Put_Line("B trapped in sync");
raise;
when $\mathrm{C}=>$
Put_Line ("C trapped in sync");
raise $D$;
end;
end Sync;
exception
when $\mathrm{A} \stackrel{\rightharpoonup}{\mathrm{a}}$
Put_Line ("A trapped in block Z");
when $\mathrm{B}=>$
Put_Line ("B trapped in block Z") ;
raise $\mathrm{C}$;
when others $=>$
Put_Line("others trapped in $\mathrm{Z"}$ );
raise $C$;
end; -- block Z
exception
when $\mathrm{C}=>$
Put_Iine ("C trapped in $\mathrm{Y}$ ");
when others $=>$
Put Line("others trapped in $\mathrm{Y}$ ");
raise $\mathrm{C}$;
end; -- block $Y$
exception
when $\mathrm{A} \quad \Rightarrow$
Put_Line ("A trapped in X") ;
when others $\Rightarrow$
Put_Line("others trapped in X");
end; -- block $X$ and task TWO
begin -- procedure main
nul1;
exception
when $\mathrm{A} \Rightarrow>$
Put_Line("A trapped in main");
when $\mathrm{B} \Rightarrow$
Put_Line("B trapped in main");
when $\mathrm{C} \Rightarrow$
Put_Line("C trapped in main");
when $\mathrm{D} \Rightarrow$
Put__Line ("D trapped in main");
end Main;
The procedure Put_Line is declared in the package Text_Io, and when called it prints its argument on the terminal.
What output would appear if the Service procedure:
(1) raised exception $\mathrm{A}$ ?
(2) raised exception $B$ ?
(3) raised exception $\mathrm{C}$ ?
(4) raised exception $D$ ?
Assume that output does not become intermingled by concurrent calls to Put_Line.