From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM,XPRIO autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,88076dc693273166,start X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-01-03 13:00:26 PST Path: archiver1.google.com!news2.google.com!fu-berlin.de!news.eunet.no!news.powertech.no!newsfeed1.e.nsc.no!nsc.no!nextra.com!news2.e.nsc.no.POSTED!53ab2750!not-for-mail From: "Frank" Newsgroups: comp.lang.ada Subject: To raise an exception in task and handle/catch it in outer-block. X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Message-ID: NNTP-Posting-Host: 130.67.131.79 X-Complaints-To: news-abuse@telenor.net NNTP-Posting-Date: Sat, 03 Jan 2004 22:00:19 MET X-Trace: news2.ulv.nextra.no 1073163619 130.67.131.79 Date: Sat, 3 Jan 2004 21:58:08 -0800 Xref: archiver1.google.com comp.lang.ada:4083 Date: 2004-01-03T21:58:08-08:00 List-Id: Hi! What is the best practice for handling exceptions (by outer block) that are raised in tasks? My question is in particular, if the approach I have chosen in the example below is recommended or not? What I have tried, is that a task raises an exception. The outer block is still waiting to perform "Stop" and "Final". In this solution I have added two accepts for "Stop" and "Final" in the exception-block of the task, to catch the client-code's "Stop" and "Final". What is the best way of handling this? To start testing "Is_Callable" or similar clutters the code in my opinion. Frank package Test_Task_Exception is task type A_Task is entry Init( P_Fail : in Boolean) ; entry Start; entry Stop; entry Final; end A_Task; end Test_Task_Exception; with Ada.Text_IO; package body Test_Task_Exception is test_exception : exception; task body A_Task is Run : Boolean := False; Counter : Integer := 0; Fail : Boolean; begin accept Init ( P_Fail : in Boolean) do Ada.Text_IO.Put_Line ("Test_Task_Exception.A_Task.Init - Body"); Fail := P_Fail; end Init; accept Start do Ada.Text_IO.Put_Line ("Test_Task_Exception.A_Task.Start - Body"); Run := True; end Start; while Run loop Counter := Counter + 1; Ada.Text_IO.Put_Line("Test_Task_Exception.A_Task.Task Working " & Counter'Img); if Counter > 8 and not Fail then select accept Stop do Ada.Text_IO.Put_Line ("Test_Task_Exception.A_Task.Stop - Body"); Run := False; end Stop; else null; end select; end if; if Counter > 8 and Fail then raise test_exception; end if; end loop; accept Final do Ada.Text_IO.Put_Line ("Test_Task_Exception.A_Task.Final - Body"); end Final; exception when others => begin accept Stop do Ada.Text_IO.Put_Line ("Test_Task_Exception.A_Task.Stop - Exception"); end Stop; accept Final do Ada.Text_IO.Put_Line ("Test_Task_Exception.A_Task.Final - Exception"); raise test_exception; end Final; end; end A_Task; end Test_Task_Exception; with Test_Task_Exception; use Test_Task_Exception; with Text_IO; use Text_IO; procedure Test_Task_Main is type Pointer_To_A_Task is access Test_Task_Exception.A_Task; Task1, Task2 : Pointer_To_A_Task; begin Put_Line("Main program"); Task1 := new Test_Task_Exception.A_Task; Task2 := new Test_Task_Exception.A_Task; Put_Line("*************** Raise no exception"); Task1.Init (False); Task1.Start; Task1.Stop; Task1.Final; Put_Line("*************** Do raise exception"); Task2.Init (True); Task2.Start; Task2.Stop; Task2.Final; end Test_Task_Main;