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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,8520d8902b684d8a X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local01.nntp.dca.giganews.com!nntp.megapath.net!news.megapath.net.POSTED!not-for-mail NNTP-Posting-Date: Tue, 22 Nov 2005 18:02:12 -0600 From: "Randy Brukardt" Newsgroups: comp.lang.ada References: <1132687889.831797.109510@o13g2000cwo.googlegroups.com> Subject: Re: Extended Return Statement with exception Date: Tue, 22 Nov 2005 18:06:18 -0600 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4952.2800 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4952.2800 Message-ID: NNTP-Posting-Host: 64.32.209.38 X-Trace: sv3-eeEETs2Ro9g4862KhAd8nvMQUq60AitxngNR1l9Oszfp7vZH8A3ceSWcEdbtZmfXSjpq/y5C4P6DYNg!EnLzZCvpV5rQ+HOX5B+PWW0eBGc83L1knLB3eMIEJBmBuvWZBhgtzVmAZNM9WLQTm+RgqLYqBDL1!tK9/L3zIK/yYCQ== X-Complaints-To: abuse@megapath.net X-DMCA-Complaints-To: abuse@megapath.net X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.32 Xref: g2news1.google.com comp.lang.ada:6536 Date: 2005-11-22T18:06:18-06:00 List-Id: "Anh Vo" wrote in message news:1132687889.831797.109510@o13g2000cwo.googlegroups.com... > I have read the Extended Return Statement in Ada 2005 RM and Rationale. > However, I am still not sure how it works. In other word, what will be > returned when an exception occurs and handled the the exception handler > within this extended return statement. Consider the following notional > code, what exactly will be returned? > > type T is limited ... > ... > > function Make (...) return T is > begin > ... > return R : T do > ... > ... -- Constraint_Error is raised here for example > exception > when Constraint_Error => null; -- handle Constraint_Error here. > end return; > end Make; (I changed your example a bit to be clear.) The answer is that if the extended return completes normally, it's object is returned. So, in this example, R is returned. You could complain that the object isn't properly initialized, but of course if you put a handler here, you ought to set up the object correctly (that is, if you handle the exception, you really need to handle it, not just ignore it). If you don't want to return R, you need to handle the exception outside of the return statement: function Make (...) return T is begin ... begin return R : T do ... ... -- Constraint_Error is raised here for example end return; exception when Constraint_Error => return Some_Default_Value; -- handle Constraint_Error here. end; end Make; There are some interesting interactions between exceptions, finalization, and return statements (imagine T has tasks or controlled components to make your head hurt), but these shouldn't be a concern for anyone other than implementers. Randy.