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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,88076dc693273166 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2004-01-04 04:01:04 PST Path: archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!zeus.visi.com!green.octanews.net!news.octanews.net!news-out.visi.com!petbe.visi.com!news.tele.dk!news.tele.dk!small.news.tele.dk!uninett.no!newsfeed1.e.nsc.no!nsc.no!nextra.com!news2.e.nsc.no.POSTED!53ab2750!not-for-mail From: "Frank" Newsgroups: comp.lang.ada References: Subject: Re: 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: <3gTJb.369$Mb5.7531@news2.e.nsc.no> NNTP-Posting-Host: 148.122.129.8 X-Complaints-To: news-abuse@telenor.net NNTP-Posting-Date: Sun, 04 Jan 2004 13:01:03 MET X-Trace: news2.ulv.nextra.no 1073217663 148.122.129.8 Date: Sun, 4 Jan 2004 12:58:52 -0800 Xref: archiver1.google.com comp.lang.ada:4096 Date: 2004-01-04T12:58:52-08:00 List-Id: Hi! I agree that the exception has nothing to do with the Stop/Final accept. What I try to achieve is that the exception is propagated to the outer block. In this case with outer block, I mean the block that controls the task- in my example "Test_Task_Main"*. This issue came up because a exception raised in a task like this is not propagated automatically by Ada to the outer block, but is resolved within each task. Another reason why is that the exception is related to the outer-block or more precisely the developer of the outer block. I wish to propagate the exception in the task for the outer-block(*) to handle it there. In my real-code, the situation is that a library Im working on, requires an abstract subprogram to be overridden. This abstract subprogram is called from within the library itself and it is in that environment that an exception may be detected. The business-related exception ("test_exception") will be raised if the developer of the abstract subprogram behaves bad. If such a exception is detected, I wish to communicate this to the outer-block(*). One question I have, is if this kind of construction is allowed in respect to Ada standard. This is a pseudo-code based on the example, here I have included the call to the abstract subprogram: package body Test_Task_Exception is test_exception : exception; task body A_Task is Run : Boolean := False; begin accept Init do -- ... as in example accept Start do -- ... as in example while Run loop -- This is an abstract subprogram, overriden by the developer using this library. -- If the return value is bad, we wish to communicate this to the outer-block Retur_Value := Do_Business_Logic(....); if Retur_Value = Bad_Value then raise test_exception; end if; -- Return_Value is ok, we are allowed to stop normally.l 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 loop; accept Final do -- ... as in example exception when others => begin accept Stop do -- ... as in example accept Final do -- repeated here for clarity Ada.Text_IO.Put_Line ("Test_Task_Exception.A_Task.Final - Exception"); -- We wish to communicate exception to the outer-block raise test_exception; end Final; end; end A_Task; end Test_Task_Exception; Frank wrote in message news:Z_GJb.739626$Fm2.662614@attbi_s04... > Personally, I would find it somewhat clearer to enclose the stuff that > may have/handle exceptions in a block of its own, rather than the task's > begin-end block. That makes it clearer that exception handling has > nothing to do with whether the task finishes up with an "accept Stop" etc. > > task body A_Task is > begin > begin > do stuff > exception > when others => do stuff > end; > accept Stop... > end A_Task;