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,999932ecc319322a X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!newsfeed2.dallas1.level3.net!news.level3.com!newsfeed-00.mathworks.com!nntp.TheWorld.com!not-for-mail From: Robert A Duff Newsgroups: comp.lang.ada Subject: Re: advice on package design Date: 17 Mar 2005 15:55:35 -0500 Organization: The World Public Access UNIX, Brookline, MA Message-ID: References: <1110212638.336123.298580@l41g2000cwc.googlegroups.com> <1gbk0qx2sgzpg$.sltzfssofla8$.dlg@40tude.net> <3jok3ghqqls8$.1rrsonb8jsurt$.dlg@40tude.net> <88zllqj1min5$.fqqxis9i327d$.dlg@40tude.net> <18e9a92kz25wu$.8b965bel5vef$.dlg@40tude.net> <1dgodaruwhhwo$.1baazg490isjx.dlg@40tude.net> NNTP-Posting-Host: shell01-e.theworld.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: pcls4.std.com 1111092935 14531 69.38.147.31 (17 Mar 2005 20:55:35 GMT) X-Complaints-To: abuse@TheWorld.com NNTP-Posting-Date: Thu, 17 Mar 2005 20:55:35 +0000 (UTC) User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: g2news1.google.com comp.lang.ada:9564 Date: 2005-03-17T15:55:35-05:00 List-Id: Martin Dowie writes: > The bit about declarations and statements I don't like is where > exceptions occur... > > e.g. > > with Ada.Text_IO; use Ada.Text_IO; > procedure Main is > function Foo (I : Integer) return Integer is > I2 : Integer := I + 1; > begin > return I2; > exception > when others => > return 0; > end Foo; > > procedure Bar is > I : Integer; > begin > I := Foo (Integer'Last); > end Bar; > begin > Bar; > exception > when others => > Put_Line ("Rats... why not catch it in 'Foo'?"); > end Main; > > I've never understood why this needs to be this way... Because I2 is visible in the handler. But it's declaration is never successfully elaborated, so it does not exist! procedure P is X: Integer := F(...); -- raises Some_Error Y: Integer := 123; begin ... exception when Some_Error => Put(X); Put(Y); -- What are the values of X and Y here? end P; Or worse: procedure P is X: Integer := F(...); -- raises Some_Error Y: String := Read_Line; begin ... exception when Some_Error => Put(Y); end P; At the point of "Put(Y);", not even the bounds of Y have been calculated, much less its value. But you're right -- the syntax is somewhat confusing, since the exception handler *looks* like it handles exceptions for the whole procedure. Another reason to get rid of declarative parts. ;-) I think a better syntax would a separate statement -- like try/catch in Java. That makes it clear what region of code is protected by the handler. - Bob