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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Received: by 2002:ac8:1a45:: with SMTP id q5mr17240797qtk.345.1568137975335; Tue, 10 Sep 2019 10:52:55 -0700 (PDT) X-Received: by 2002:a9d:77d1:: with SMTP id w17mr6117910otl.5.1568137974923; Tue, 10 Sep 2019 10:52:54 -0700 (PDT) Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!weretis.net!feeder6.news.weretis.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!o24no5683503qtl.0!news-out.google.com!q23ni115qtl.1!nntp.google.com!o24no5683497qtl.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.ada Date: Tue, 10 Sep 2019 10:52:54 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=192.160.103.146; posting-account=1tLBmgoAAAAfy5sC3GUezzrpVNronPA- NNTP-Posting-Host: 192.160.103.146 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: Subject: potential Ada feature - comments? From: Matt Borchers Injection-Date: Tue, 10 Sep 2019 17:52:55 +0000 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Xref: reader01.eternal-september.org comp.lang.ada:57126 Date: 2019-09-10T10:52:54-07:00 List-Id: I often find myself writing the same code fragment in exception handlers. = That is, I catch and handle the specific exceptions and the cleanup code fo= r the subprogram is identical. I know that I can (and do) write a cleanup = routine to handle this, but even so, the call to the cleanup routine must s= till be added to every exception case in the handler. procedure SUBPROGRAM is procedure CLEANUP is begin --free resources ... end CLEANUP; begin --acquire resources ... exception when X =3D> --something for X cleanup; when Y =3D> --something for Y cleanup; when Z =3D> --something for Z cleanup; when others =3D> --general case cleanup; end SUBPROGRAM; I propose something like the following: begin --acquire resources ... exception when X =3D> --something specific for X ... when Y =3D> --something specific for Y ... when Z =3D> --something specific for Z ... when others =3D> --general case ... finally --free resources ... end SUBPROGRAM; The code in the finally block would run immediately before the stack frame = is removed for the SUBPROGRAM regardless of whether the exception is re-rai= sed. I would expect that the 'finally' block would only be allowed immedia= tely after an 'exception' handler block. The following would NOT be allowe= d: begin ... finally --syntax error: finally must follow exception handler cleanup; end SUBPROGRAM; What do you all think? 1) It eliminates redundant code. 2) It eliminates a nested and unnecessary cleanup routine. 3) It would make me feel better when writing exception handlers. Matt