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-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,9127c759a41fcfda X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-08-05 11:22:49 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!logbridge.uoregon.edu!kibo.news.demon.net!demon!peernews!peer.cwci.net!newspeer1-gui.server.ntli.net!ntli.net!news13-win.server.ntlworld.com.POSTED!not-for-mail From: "chris.danx" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.1b) Gecko/20020721 X-Accept-Language: en-gb, en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: [ot... well kindof] SDI References: <5ee5b646.0208040616.77f0460a@posting.google.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Inktomi-Trace: pc3-bbrg1-2-cust234.ren.cable.ntl.com 1028571768 9260 80.5.140.234 (5 Aug 2002 18:22:48 GMT) Message-ID: Date: Mon, 05 Aug 2002 19:22:07 +0100 NNTP-Posting-Host: 80.3.128.4 X-Complaints-To: abuse@ntlworld.com X-Trace: news13-win.server.ntlworld.com 1028571768 80.3.128.4 (Mon, 05 Aug 2002 19:22:48 BST) NNTP-Posting-Date: Mon, 05 Aug 2002 19:22:48 BST Organization: ntl News Service Xref: archiver1.google.com comp.lang.ada:27720 Date: 2002-08-05T19:22:07+01:00 List-Id: Chad R. Meiners wrote: > "chris.danx" wrote in message >> - "the following procedures use result codes: >> ... >> >> Modify the procedures to use exceptions instead, ensuring that the >> effect is the same." > > > I think this question would be suitable here since you can show both > versions of the code and ask specific questions about the codes' > equivalance. this is the original code. subtype Postcode is String (1..7); type PersonRecord is record name : ...; address : ... pc : Postcode; end record; -- Read a postcode from standard input into code. -- Set ok to true if and only if that post code is -- well-formed. -- procedure get_postcode (pc : out Postcode; ok : out Boolean) is begin get (pc); ok := is_letter(pc(1)) and ...; end get_postcode; -- Read complete personal details from standard input into person, -- interactively promting the user for each detail. -- procedure get_personal_details (person : out PersonRecord) is pc_ok : Boolean; begin ... -- read person.name and person.address. loop put ("enter postcode"); get_postcode (person.pc, pc_ok); exit when pc_ok; put_line ("postcode is ill-formed!"); end loop; end get_personal_details This is my revision to make it work with exceptions instead. subtype Postcode is String (1..7); type PersonRecord is record name : ...; address : ... pc : Postcode; end record; postcode_error : exception; -- return true if pc is well-formed, false otherwise. -- -- I prefer this since postcode formats may change in future, -- this makes a change easier! -- function is_wellformed (pc : in postcode) return boolean is ...; -- Read a postcode from standard input into code. -- -- raises a Postcode_Error exception if the postcode is ill-formed. -- procedure get_postcode (pc : out Postcode) is begin get(pc); if not is_wellformed (pc) then raise Postcode_Error; end if; end get_postcode; -- Read complete personal details from standard input into person, -- interactively promting the user for each detail. -- procedure get_personal_detials (person : out PersonRecord) is begin ... -- read person.name and person.address. loop begin put ("enter postcode"); get_postcode (person.pc, pc_ok); exit; -- ??? exception when Postcode_Error => Put_Line ("Postcode is ill-formed!"); end; end loop; end get_personal_details My concern is at the line marked "-- ???" the code will just exit the begin-end block not the loop, is this correct? If so a simple revision that introduced a flag set after get_postcode would do. The effect of the code has to be the same, that is it must loop until a valid postcode is entered. Chris -- to reply change 'spamoff' to 'chris'