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,1e4bb63e08046e1a X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2002-10-25 08:06:12 PST Newsgroups: comp.lang.ada Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!canoe.uoregon.edu!logbridge.uoregon.edu!uunet!sea.uu.net!sac.uu.net!ash.uu.net!world!news From: Robert A Duff Subject: Re: is exception when others => null; smart? User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Sender: news@world.std.com (Mr Usenet Himself) Message-ID: Date: Fri, 25 Oct 2002 15:04:48 GMT Content-Type: text/plain; charset=us-ascii References: NNTP-Posting-Host: shell01.theworld.com Mime-Version: 1.0 Organization: The World Public Access UNIX, Brookline, MA Xref: archiver1.google.com comp.lang.ada:30133 Date: 2002-10-25T15:04:48+00:00 List-Id: "Per Sandbergs" writes: > 1) > main_loop: > loop > begin > lots of operations. > exception > when others => > report the error and reset top a safe state in order to continue. > end loop; > > 2) > function work_is_ok(fool) return boolean is > begin > some computations > exception -- > when others => > return false; -- or report error and eventualt raise. > end; > 2) > procedure must_not_raie(fool) is > begin > some computations > exception > when others => > null; > end; > So when others => null is only to be used when you are expecting the > unexpected. > I wont be supprised if other peoplen are of different opinion but after > integration a number of large systems i find the above aproach "wise". Also, 4) when others => clean up; raise; As in: procedure Walk_Tree(...) is begin Push current node on stack; walk subtrees; Pop stack; exception when others => Pop stack; -- Keep stack in synch even in case of exception. raise; end Walk_Tree; Finalization can also be used for this purpose, and that's a cleaner way to do it, but finalization is *very* expensive in most Ada compilers, whereas the above "when others" is pretty cheap. - Bob