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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,7d3cb5920e882220 X-Google-Attributes: gid103376,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!out02b.usenetserver.com!news.usenetserver.com!in01.usenetserver.com!news.usenetserver.com!news-out1.kabelfoon.nl!newsfeed.kabelfoon.nl!xindi.nntp.kabelfoon.nl!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Exceptions Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <5947aa62-2547-4fbb-bc46-1111b4a0dcc9@x69g2000hsx.googlegroups.com> <475c6ed8$0$13111$9b4e6d93@newsspool2.arcor-online.net> <1kxk3hlfa25dw$.fl2wvbn0tpbg$.dlg@40tude.net> <475d296a$0$27813$4f793bc4@news.tdc.fi> Date: Mon, 10 Dec 2007 14:08:50 +0100 Message-ID: <12mjar2f2t2e6$.o2upq0n29j1f.dlg@40tude.net> NNTP-Posting-Date: 10 Dec 2007 14:01:07 CET NNTP-Posting-Host: f8dd646f.newsspool1.arcor-online.net X-Trace: DXC=Xmd0^aFo>[geoCI^f\Y]Eaic==]BZ:afn4Fo<]lROoRa4nDHegD_]ReP^;41nXjmgcDNcfSJ;bb[eFCTGGVUmh?dLK[5LiR>kgbP On Mon, 10 Dec 2007 14:09:31 +0200, Niklas Holsti wrote: > Dmitry A. Kazakov wrote: > > > [some questions, see below] > > I'm not sure if Dmitry really wants answers to his questions below > -- perhaps they were merely rhetorical -- but they tickled my > curiosity, so here is one data point from my main Ada application: Thank you for the figures. It is really interesting. >> 1. How often do you declare a new exception when writing a new subprogram? >> My guess is about 1 / 10_000. > > From the numbers above: 87 / 6_292 = 138 / 10_000. One per hundred also. As for me I tend to reuse IO_Exceptions if semantics is close, so my figure should be much lesser. > In some cases > one declared exception can be raised in several subprograms, but I > think the average number of subprograms that can raise a given > application-defined exception is between 1 and 2, not larger, in > this application. This is a very low figure. But as I said, I reuse exceptions much. A possible danger is to overload an exception too much (like Constraint_Error already is). This is IMO a question of custom and also of the language design. When exceptions tend to propagate out of the application, one would certainly like to make them "meaningful" indicating the fault reason as precise as possible. This is not what I wanted from Ada. I'd like to have all exceptions handled. So I treat them rather as signals within and for the application. I don't buy exceptions as a debugging tool. >> 2. How often does a caller "eat" an exception of the callee instead of >> propagating it further? My guess is 1 / 10. > > My numbers do not separate between exceptions propagated from calls > and exceptions raised within the handled sequence-of-statements > itself. But my feeling is that at least half of the handlers are > meant to catch exception from calls, and I don't think that there > is any systematic difference in the proportion of "eaters" versus > "propagators" between the two cases. > > So, from the above numbers, "eaters" / "all handlers" = 180 / 275 = > 6.5 / 10. Interesting. I didn't measured my code, but I expect more scopes where exceptions propagate unhandled. That depends on how much refactoring is done. Actually, I have an impression that many exception-related bugs appear while code refactoring and other small apparently equivalent code modifications, which in turn are not almost equivalent. >> There is not that many handlers in a good designed code. > > That is too generalized. I think that the number of handlers is > partly a matter of personal style (preference for error-code > parameters vs exceptions) and partly depends on the required level > of error tolerance (ability to continue processing in spite of > errors). Yes > Good error tolerance may require more local handlers to > clean up local state, before (possibly) passing the exception to > higher levels. Possibly, however there is a concurring mechanism for clean-ups, I mean controlled types. In many cases Finalize does what otherwise a handler would. > The application behind the numbers given above is not required to > be error-tolerant. Thus, many exceptions can simply be propagated > to a high level, without passing through many local clean-up > handlers on the way. Yes, but again it is probably not about being error-[in]tolerant. I think the overall code structure plays a role here. When I refactor small subprogram doing this or that thing, I often leave exception handling functionality to another piece of code. Maybe this is my personal motivation behind longing for contracted exceptions. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de