comp.lang.ada
 help / color / mirror / Atom feed
From: Niklas Holsti <niklas.holsti@tidorum.invalid>
Subject: Re: Exceptions
Date: Mon, 10 Dec 2007 14:09:31 +0200
Date: 2007-12-10T14:09:31+02:00	[thread overview]
Message-ID: <475d296a$0$27813$4f793bc4@news.tdc.fi> (raw)
In-Reply-To: <1kxk3hlfa25dw$.fl2wvbn0tpbg$.dlg@40tude.net>

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:

Number of packages (.ads files)                   :     196
Number of package bodies (.adb files)             :     147
Total source lines (including blanks and comments): 201_731
Total number of lines with semicolons             :  42_935
Total number of subprograms                       :   6_292

Exceptions declared                               :      87

Explicit raise statements (with exception name)   :     239
- of Constraint_Error (note 1)                    :      20
- of Program_Error    (note 1)                    :      12
- of application-defined exceptions               :     207

Exception-handler sequences (note 2)              :     219
Exception handlers (note 3)                       :     275

Handlers that "eat "exceptions (note 4)           :     180
- eat specific application-defined exception(s)   :     129
- eat specific language-defined exception(s)      :      34
- eat "others"                                    :      17

Handlers that raise or re-raise exceptions        :     102
- propagate same application-defined exception    :      13
- propagate same language-defined exception       :      22
- propagate same "others" exception               :      28
- change app-def. exc. to other app-def. exc.     :      20
- change language-def. exc. to app-def. exc.      :      18
- change app-def. exc. to language-def. exc.      :       1


Notes:
   1. Of the language-defined exceptions, only
      Constraint_Error and Program_Error are raised
      explicitly (by "raise <name>").
   2. An "exception-handler sequence" is the list of
      exception_handlers at the end of a handled_-
      sequence_of_statements.
   3. Whether for one exception, several exceptions,
      or "others".
   4. Handlers that do not contain "raise" statements.

Some of the above was counted by hand from "grep" outputs, so the 
numbers may be off by a couple of units.

It is noteworthy that most exception-handler sequences (total: 219) 
only have one exception handler (total: 275), although this single 
handler often handles several exceptions, or "others".

> 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. 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.

> 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.

> 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). Good error tolerance may require more local handlers to 
clean up local state, before (possibly) passing the exception to 
higher levels.

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.

-- 
Niklas Holsti
Tidorum Ltd
niklas holsti tidorum fi
       .      @       .



  parent reply	other threads:[~2007-12-10 12:09 UTC|newest]

Thread overview: 100+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-12-06 15:00 Exceptions shaunpatterson
2007-12-06 21:24 ` Exceptions tmoran
2007-12-07  8:54   ` Exceptions Dmitry A. Kazakov
2007-12-07 10:21     ` Exceptions Georg Bauhaus
2007-12-07 15:11       ` Exceptions shaunpatterson
2007-12-07 16:08         ` Exceptions Gautier
2007-12-07 18:56         ` Exceptions Simon Wright
2007-12-08 10:04         ` Exceptions Stephen Leake
2007-12-08  3:30     ` Exceptions Randy Brukardt
2007-12-08 10:09       ` Contracted exceptions for Ada (was: Exceptions) Dmitry A. Kazakov
2007-12-09 10:22         ` Contracted exceptions for Ada Stephen Leake
2007-12-09 11:02           ` Dmitry A. Kazakov
2007-12-11  8:10             ` Stephen Leake
2007-12-11 10:36               ` Dmitry A. Kazakov
2007-12-09 15:11         ` Contracted exceptions for Ada (was: Exceptions) Martin Krischik
2007-12-09 17:36           ` Contracted exceptions for Ada Dmitry A. Kazakov
2007-12-09 18:39             ` Simon Wright
2007-12-10  8:19               ` Dmitry A. Kazakov
2007-12-10 20:25                 ` Simon Wright
2007-12-11  8:50                   ` Dmitry A. Kazakov
2007-12-11 20:50                     ` Simon Wright
2007-12-12 10:20                       ` Dmitry A. Kazakov
2007-12-09 19:04             ` Martin Krischik
2007-12-10  8:20               ` Dmitry A. Kazakov
2007-12-09 22:09         ` Robert A Duff
2007-12-10  7:09           ` Stefan Lucks
2007-12-10 16:57             ` Robert A Duff
2007-12-11  1:53         ` Contracted exceptions for Ada (was: Exceptions) Randy Brukardt
2007-12-11  9:16           ` Contracted exceptions for Ada Dmitry A. Kazakov
2007-12-12  0:26             ` Randy Brukardt
2007-12-08 12:26       ` Exceptions Peter C. Chapin
2007-12-08 14:01         ` Exceptions Dmitry A. Kazakov
2007-12-08 18:01           ` Exceptions Peter C. Chapin
2007-12-09 10:06             ` Exceptions Dmitry A. Kazakov
2007-12-09 12:40               ` Exceptions Peter C. Chapin
2007-12-09 14:31                 ` Exceptions Dmitry A. Kazakov
2007-12-09 16:38                   ` Exceptions Peter C. Chapin
2007-12-10  8:31                     ` Exceptions Dmitry A. Kazakov
2007-12-09 21:56                 ` Exceptions Robert A Duff
2007-12-09 10:24             ` Exceptions Stephen Leake
2007-12-09 12:46               ` Exceptions Peter C. Chapin
2007-12-09 21:39   ` Exceptions Robert A Duff
2007-12-09 22:13     ` Exceptions Georg Bauhaus
2007-12-11  8:07       ` Exceptions Stephen Leake
2007-12-11 20:28         ` Exceptions Simon Wright
2007-12-12 22:10         ` Exceptions Maciej Sobczak
2007-12-13 13:40           ` Exceptions Robert A Duff
2007-12-13 14:00             ` Exceptions Maciej Sobczak
2007-12-13 14:44               ` Exceptions Robert A Duff
2007-12-14  0:46                 ` Exceptions Ray Blaak
2007-12-14  2:36                   ` Exceptions Randy Brukardt
2007-12-14  6:21                     ` Exceptions Ray Blaak
2007-12-14 12:40                       ` Exceptions Georg Bauhaus
2007-12-14 17:29                   ` Exceptions Robert A Duff
2007-12-14 19:32                     ` Exceptions Dmitry A. Kazakov
2007-12-15  5:29                     ` Exceptions Ray Blaak
2007-12-13 19:29               ` Exceptions Randy Brukardt
2007-12-12 19:18     ` Exceptions Martin Krischik
2007-12-13 13:27       ` Exceptions Robert A Duff
2007-12-13 23:25       ` Exceptions Ray Blaak
2007-12-06 21:25 ` Exceptions Gautier
2007-12-07  4:29 ` Exceptions anon
2007-12-07  4:43 ` Exceptions, part 2 anon
2007-12-07 16:55 ` Exceptions Adam Beneschan
2007-12-07 18:59   ` Exceptions Simon Wright
2007-12-08  0:38     ` Exceptions Adam Beneschan
2007-12-09 21:45     ` Exceptions Robert A Duff
2007-12-09 22:40       ` Exceptions Georg Bauhaus
2007-12-10  8:22         ` Exceptions Dmitry A. Kazakov
2007-12-10  9:20           ` Exceptions Georg Bauhaus
2007-12-10  9:30             ` Exceptions Georg Bauhaus
2007-12-10 10:56             ` Exceptions Dmitry A. Kazakov
2007-12-11  2:18               ` Exceptions Randy Brukardt
2007-12-11  8:19               ` Exceptions Georg Bauhaus
2007-12-11 11:55                 ` Exceptions Dmitry A. Kazakov
2007-12-11 16:13                   ` Exceptions Georg Bauhaus
2007-12-12 11:18                     ` Exceptions Dmitry A. Kazakov
2007-12-10 12:09           ` Niklas Holsti [this message]
2007-12-10 13:08             ` Exceptions Dmitry A. Kazakov
2007-12-10 20:02               ` Exceptions Niklas Holsti
2007-12-11 12:31                 ` Exceptions Dmitry A. Kazakov
2007-12-11 13:21                   ` Exceptions Niklas Holsti
2007-12-12  0:01                     ` Exceptions Randy Brukardt
2007-12-12 11:37                       ` Exceptions Niklas Holsti
2007-12-12 13:14                         ` Exceptions Dmitry A. Kazakov
2007-12-12 14:37                       ` Exceptions Robert A Duff
2007-12-13 19:20                         ` Exceptions Randy Brukardt
2007-12-13 20:15                           ` Exceptions Robert A Duff
2007-12-12 11:00                     ` Exceptions Dmitry A. Kazakov
2007-12-11  2:12           ` Exceptions Randy Brukardt
2007-12-11 15:17             ` Exceptions Robert A Duff
2007-12-12  0:10               ` Exceptions Randy Brukardt
2007-12-13 19:58                 ` Exceptions Robert A Duff
2007-12-14  0:53                 ` Exceptions Ray Blaak
2007-12-14  2:48                   ` Exceptions Randy Brukardt
2007-12-14  6:33                     ` Exceptions Ray Blaak
2007-12-08 10:03 ` Exceptions Stephen Leake
  -- strict thread matches above, loose matches on Subject: below --
1991-03-06 17:24 Exceptions David Erickson
1991-03-06 21:21 ` Exceptions Jerry Callen
1989-06-23 21:57 Exceptions howell
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox