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=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!mx02.eternal-september.org!feeder.eternal-september.org!gandalf.srv.welterde.de!news.jacob-sparre.dk!loke.jacob-sparre.dk!pnx.dk!.POSTED!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: function Is_Open (File : File_Type) return Boolean; :Text_io Date: Wed, 28 Oct 2015 12:58:30 -0500 Organization: JSA Research & Innovation Message-ID: References: <87twpd2qlo.fsf@theworld.com> <1pj15r7pul7f1.15qgdyrc8k133$.dlg@40tude.net> <87pp0030c1.fsf@theworld.com> <135hiczk56x02.1xixcme8btbl4.dlg@40tude.net> <1dzlgoh4u2j7t$.1un3dfy0oeigd$.dlg@40tude.net> NNTP-Posting-Host: rrsoftware.com X-Trace: loke.gir.dk 1446055110 28332 24.196.82.226 (28 Oct 2015 17:58:30 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Wed, 28 Oct 2015 17:58:30 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.5931 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.6157 X-RFC2646: Format=Flowed; Response Xref: news.eternal-september.org comp.lang.ada:28091 Date: 2015-10-28T12:58:30-05:00 List-Id: "Georg Bauhaus" wrote in message news:n0qa3q$th8$1@dont-email.me... ... > "Better than Assertion_Error?" I understand we are going to get > > subtype Open_File is File with Predicate => > Is_Open(Open_File) or else raise Status_Error with "..."; You need to use the aspect Predicate_Failure here, as opposed to raising an exception in the predicate expression. (That's different than in a precondition.) In this case (and replacing the Gnat-only "predicate" aspect): subtype Open_File is File with Dynamic_Predicate => Is_Open(Open_File), Predicate_Failure => raise Status_Error with "..."; Else bad things might happen to membership tests: if My_File in Open_File then Call_Subprogram_That_Requires_an_Open_File (My_File); end if; If My_File is not open, this membership and your subtype would raise Status_Error, not False. (This was a tough nut to crack for the ARG. And GNAT only recently implemented Predicate_Failure, so with older GNATs you have to leave the exception alone.) Randy.