comp.lang.ada
 help / color / mirror / Atom feed
From: Brian May <bam@snoopy.apana.org.au>
Subject: Re: Java exception model. Was: Re: Ada Quality and Style book discussion ("_Type" suffix)
Date: Tue, 22 Nov 2005 10:27:25 +1100
Date: 2005-11-22T10:27:25+11:00	[thread overview]
Message-ID: <sa47jb1oa3m.fsf@snoopy.microcomaustralia.com.au> (raw)
In-Reply-To: nd2n8m0awfve$.153qc2267anaq$.dlg@40tude.net

>>>>> "Dmitry" == Dmitry A Kazakov <mailbox@dmitry-kazakov.de> writes:

    Dmitry> I think it is reasonable. What Java probably lacks is a
    Dmitry> good way of composition of exception contracts, like "X
    Dmitry> raises what Y does except that ones mentioned in Z."

One issue that is not always clear is how exceptions should be handled
low level routines.

For example, append_mail might be a function that writes a new email
to the users mailbox. Initially the designers decide it might through the
following exceptions:

ERROR_QUOTA_EXCEEDED
ERROR_PERMISSION_DENIED

Later on, the function is expanded to support different formats, e.g.
LMTP, IMAP, etc.

Eventually, one day, a low level routine used by append_mail returns
the exception:

ERROR_OUT_OF_PAPER

What does append_mail do?


It could:

a) return ERROR_OUT_OF_PAPER to calling subroutine, but should the
calling subroutine really have to deal with a printer error? It
doesn't even know the output is going to a printer. Also, should it
really have to deal with network errors? What about LDAP errors,
Kerberos authentication errors, errors creating temporary files, etc?

Yes, it could catch all exceptions, just in case; I am not convinced
this is a good solution.

b) turn the exception into a generic exception for append_mail,
ERROR_APPEND_MAIL, this might make it harder to locate the actual
source of the exception. This I think is my preferred solution, as I
consider the above exceptions private implementation details inside
append_mail, all that the calling function is interested in is the
fact an error occurred, and possibly a string to display to the user
(but see below).

At least with the Java model, the compiler lets you know of the issue,
and you don't suddenly wake up to the fact these low level exceptions
are suddenly being used throughout your entire code.



Then, if the calling process has to generate an error to the sender,
what should the error be?

If I sent an email to somebody and got an error "Out Of Paper", I
think I might be slightly confused. Another alternative is to prefix
the message at each layer, eg:

"Error appending mail: Error sending email via LMTP: Error storing mail: Error logging email: Error writing to syslog: Error writing to printer: Out of paper."

You just need to be able to interpret such a message... I think many
users I know would still be confused, especially as it deals with
technical details specific to the mail setup of the recipient. It
probably would help the administrator though, if he ever receives a
copy of the error.

(yes, you could argue that the above error shouldn't be a fatal error,
lets assume paranoid people).

The other approaches I have seen are hardly worth mentioning:

* generic error for all errors, e.g. "Error!"

* assume error is, say incorrect password, and display verbose
  information on what the user should do to fix an incorrect password.

  (IIRC Outlook does this when accessing a remote IMAP server - and
  the user spends ages trying to work out why the password is wrong
  when the real error is totally unrelated.)
-- 
Brian May <bam@snoopy.apana.org.au>



  parent reply	other threads:[~2005-11-21 23:27 UTC|newest]

Thread overview: 112+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-15 16:03 Request for comments on simple Ada program Maciej Sobczak
2005-11-15 17:43 ` Samuel Tardieu
2005-11-15 17:47   ` Samuel Tardieu
2005-11-15 21:28   ` Jacob Sparre Andersen
2005-11-15 21:53     ` Samuel Tardieu
2005-11-16  9:10       ` Anders Wirzenius
2005-11-15 21:55     ` Samuel Tardieu
2005-11-16  9:03     ` Niklas Holsti
2005-11-16 14:21       ` Jacob Sparre Andersen
2005-11-16 17:08         ` Niklas Holsti
2005-11-16  7:11   ` Brian May
2005-11-15 18:29 ` jimmaureenrogers
2005-11-15 19:33   ` tmoran
2005-11-16 14:46     ` jimmaureenrogers
2005-11-16 18:05       ` Martin Dowie
2005-11-16 19:54       ` tmoran
2005-11-15 18:52 ` Martin Krischik
2005-11-15 19:33 ` tmoran
2005-11-16  3:10   ` Ada Quality and Style book discussion Anonymous Coward
2005-11-16  4:09     ` tmoran
2005-11-16  5:49     ` Simon Wright
2005-11-16  7:03       ` Martin Dowie
2005-11-17  4:49         ` Anonymous Coward
2005-11-17  6:48           ` Martin Dowie
2005-11-17 11:45           ` Georg Bauhaus
2005-11-17 12:37             ` Stephen Leake
2005-11-17 13:24               ` Georg Bauhaus
2005-11-17 23:15                 ` Stephen Leake
2005-11-19 20:28                   ` Don't use the "use" clause Anonymous Coward
2005-11-19 20:35                     ` Ed Falis
2005-11-21 17:36                       ` David Emery
2005-11-21 19:20                         ` Ed Falis
2005-11-21 22:21                           ` David Trudgett
2005-11-21 22:51                             ` Ed Falis
2005-11-22  0:15                           ` Anonymous Coward
2005-11-23  4:09                             ` Ed Falis
2005-11-23 19:26                               ` tmoran
2005-11-19 21:48                     ` Dmitry A. Kazakov
2005-11-19 22:33                       ` Simon Wright
2005-11-19 23:40                       ` Anonymous Coward
2005-11-20 11:07                         ` Dmitry A. Kazakov
2005-11-20 19:50                       ` Jeffrey R. Carter
2005-11-20  2:53                     ` Stephen Leake
2005-11-20  3:57                       ` Anonymous Coward
2005-11-20 10:44                     ` Pascal Obry
2005-11-20 19:48                     ` Jeffrey R. Carter
2005-11-22  5:11                     ` greptree lou
2005-11-22  6:08                       ` greptree Simon Wright
2005-11-25  1:00                       ` greptree Björn Persson
2006-01-23 12:51                     ` Don't use the "use" clause adaworks
2006-01-23 20:21                       ` Jeffrey R. Carter
2006-01-24  2:27                         ` Stephen Leake
2006-01-24  3:32                           ` Ed Falis
2006-01-24  4:44                           ` Jeffrey R. Carter
2006-01-24 22:53                             ` Stephen Leake
2006-01-24  8:54                           ` Dmitry A. Kazakov
2006-01-24  9:48                             ` Martin Dowie
2006-01-24 10:28                               ` Dmitry A. Kazakov
2006-01-24 13:30                                 ` brian.b.mcguinness
2006-01-24 20:03                                   ` Simon Wright
2006-01-24 23:00                                   ` Stephen Leake
2006-01-25  4:58                                     ` Jeffrey R. Carter
2006-01-24 23:38                                 ` Randy Brukardt
2006-01-25 14:49                                   ` Dmitry A. Kazakov
2006-01-25 21:46                                     ` Randy Brukardt
2006-01-26  9:14                                       ` Dmitry A. Kazakov
2006-01-27  1:04                                         ` Randy Brukardt
2006-01-27 15:23                                           ` Dmitry A. Kazakov
2006-01-27 16:35                                             ` Georg Bauhaus
2006-01-27 23:09                                               ` Randy Brukardt
2006-01-27 23:18                                             ` Randy Brukardt
2006-01-28 10:41                                               ` Dmitry A. Kazakov
2006-01-24 22:55                             ` Stephen Leake
2006-01-24  9:42                           ` Martin Dowie
2006-01-24 23:02                             ` Stephen Leake
2006-01-25  9:14                               ` Martin Dowie
2006-01-25 11:01                             ` Peter Amey
2006-01-25 11:06                               ` Martin Dowie
2006-01-25 20:07                               ` Jeffrey R. Carter
2006-01-31  2:24                               ` Stephen Leake
2006-02-09  5:13                       ` Anonymous Coward
2005-11-17 20:55           ` Ada Quality and Style book discussion Simon Wright
2005-11-18  0:44             ` Larry Kilgallen
2005-11-19 20:56             ` Anonymous Coward
2005-11-19 22:41               ` Simon Wright
2005-11-20  0:03                 ` Anonymous Coward
2005-11-17  4:23       ` Ada Quality and Style book discussion ("_Type" suffix) Anonymous Coward
2005-11-17 10:51         ` Martin Dowie
2005-11-19 21:52           ` Anonymous Coward
2005-11-20 15:50             ` Martin Dowie
2005-11-17 11:34         ` Georg Bauhaus
2005-11-17 11:53           ` Martin Dowie
2005-11-17 13:26             ` Georg Bauhaus
2005-11-17 12:26           ` Brian May
2005-11-17 13:45             ` Martin Dowie
2005-11-17 14:22               ` Marc A. Criley
2005-11-17 14:50                 ` Martin Dowie
2005-11-18  3:04                 ` Brian May
2005-11-18  9:23                   ` Maciej Sobczak
2005-11-18 14:00                     ` Marc A. Criley
2005-11-18 11:48                   ` Java exception model. Was: " Peter C. Chapin
2005-11-18 13:18                     ` Dmitry A. Kazakov
2005-11-19 18:06                       ` Peter C. Chapin
2005-11-19 18:58                         ` Dmitry A. Kazakov
2005-11-21 22:38                           ` Brian May
2005-11-21 23:27                           ` Brian May [this message]
2005-11-18 22:33                   ` Simon Wright
2005-11-17 14:03             ` Hyman Rosen
2005-11-20 19:41         ` Jeffrey R. Carter
2005-11-20 20:43           ` Dmitry A. Kazakov
2005-11-21  0:00             ` Simon Wright
2005-11-16 13:51     ` Ada Quality and Style book discussion Marc A. Criley
replies disabled

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