comp.lang.ada
 help / color / mirror / Atom feed
From: Stephen Leake <stephen_leake@stephe-leake.org>
Subject: Re: Structured exception information
Date: Sat, 27 Jan 2007 13:17:02 -0500
Date: 2007-01-27T13:17:02-05:00	[thread overview]
Message-ID: <uy7nomj1d.fsf@stephe-leake.org> (raw)
In-Reply-To: 1169819196.5976.57.camel@localhost.localdomain

Georg Bauhaus <bauhaus@futureapps.de> writes:

> On Fri, 2007-01-26 at 04:35 -0500, Stephen Leake wrote:
>
> I'd prefer something like
>
> procedure Write_Output
>    (Module : in Module_Type;
>     Symbol : in Symbol_Access_Type)
> is
>    User_Volts : constant Real_Type := Reals.Get (Symbol);
> begin
>    if User_Volts > Max_Volts then
>       View.Set_Error((Off_Error with
>                           Condition => Greater_Than,
>                           Required => Max_Volts,
>                           Given => User_Volts));
>       raise User_Error;
>    else
>       Write_Hardware (Module.Hardware_Device, To_Counts (User_Volts));
>    end if;
>
> end Write_Output;
>
> And then
>
> exception
>   when E : User_Error => 
>     View.Show_Error;
>       -- Uses the interface of the progenitors of Off_Error,
>       -- for the object entered using View.Set_Error.
>       -- If we had exception types, this could be
>       -- much simpler, just View.Show_Error(E).
>     View.Print(Ada.Exceptions.Get_Exception_Message (E));
> end;
>

Obviously that would work, but _why_ is it "better"? In my opinion,
it's worse, for libraries you want to distribute; you now have this
non-standard "View" library to distribute with your application.

I guess View.Show_Error might do something other than write a string
to an error log. It might put up a structured dialog box, with widgets
for each different field of the exception type. But that's a huge
amount of work, and no application I've ever seen does that.

What do you think Show_Error does here?

In addition, you have ignored the problem that each version of
Write_Output for different hardware will need need a corresponding
version of the exception type; more work.

Hmm. With the choice of names you used in Set_Error, you seem to be
implying that there is a "general error description language", that
Set_Error can enforce. I don't think that's true.

Here is a small sample of actual error messages from my application:

raise Hardware_Error with 
 "digital pot card did not respond to serial number request";

raise Hardware_Error with
  "digital pot card responded with wrong byte count to serial number" &
  request (got" & Stream_Element_Offset'Image (Data_Last) & ")";

raise Parameter_Error with
  "motor" & Integer'Image (Module.Ramp_Motor_Index) & 
  " Disable_Encoder_Model not set";

raise Device_Error with
  "can't open device " & C_Name (1 .. C_Name'Last - 1) & " : " &
  Error_Type'Image (To_Error (GNAT.OS_Lib.Errno));

(There are many, many more, of course).

Here are a couple of other 'validation' procedures that raise
exceptions:

      procedure Check_Size (Max : in Integer)
      is begin
         if Integer (Bit) + Integer (Bit_Size) > Max then
            Ada.Exceptions.Raise_Exception
              (Config_File_Error'Identity,
               File_Line_Column & " bit, bit_size overflow register");
         end if;
      end Check_Size;

      procedure Check_Direction (Port : in Port_Type)
      is begin
         if Direction /= Mode (Port) then
            Ada.Exceptions.Raise_Exception
              (Config_File_Error'Identity,
               File_Line_Column & " conflicting directions");
         end if;
      end Check_Direction;


I suppose it might be _possible_ to come up with a generic set of
exception type components that would cover all of the messages in my
application, but that's a lot of extra design work, when 'raise ...
with <string>" give the same end result much more simply.

> Absent exception types, making exception info propagation
> explicit will add some advantages, in addition to not being
> implicit as in exception strings:
>
> - message information isn't dependent on arbitrary strings in the
>   implementation of Write_Output. You'd need to recompile a
>   *validation* procedure 

I guess by "validation" you mean the check "user_volts > Max_volts",
and the Check_* procedures I quoted above.

> when the *message* should change even though the validation didn't
> change. From this viewpoint Write_Output mixes two separate
> concerns: input checking and UI message construction.

People keep saying those should be separate concerns, but I don't
accept that. Why is it _better_ that they be separate?

As far as I can tell, the _primary_ purpose of a validation procedure
is to report a problem to the user. Formatting a string is the best
way to do that.

> - Off_Error is derived from an abstract data type describing
>   failure information. A user of this type can choose a
>   suitable message constructed from the information.
>   This is both *MVC* and also *decoupling*: The procedure Write_Output
>   can be used unchanged even when error messages are to be
>   displayed using Wide_String, 

Converting String to Wide_String is trivial. 

> a pair of LEDs 

No, there is nowhere near enough expressive power in LEDs to cover all
possible error messages. This is not a viable option. 

That's like saying "I can browse the web on my cell phone". You may
have a cell phone that understands http and can format HTML, but you
can actually _use_ only the very small fraction of the web sites that
have been reworked to support small displays. This is an excellent
analogy; the _provider_ of the information has to understand the
limits of the _display_.

Yes, I am assuming something about the ultimate error display
mechanism; I'm assuming it can display String. But no-one has
presented an actual alternative that isn't equivalent to String!

> or a Spanish character set. 

I think that is a valid objection; other parts of this thread have
talked around it. My application has no (current :) requirement for
this, so I can ignore it.

But let me present what I might do if this became a real requirement.
I would try to use the Gnu gettext library. I believe (I have _not_
studied this in detail) that library allows you to define
"message_ids" that are then looked up in a message database; there are
different instances of the database for each language. In addition, I
think you can include C printf escapes in the strings.

So two of the messages above would become:

raise Hardware_Error with MESSAGE_ID_1234;

where the English version of MESSAGE_ID_1234 is
 "digital pot card did not respond to serial number request"

raise Device_Error with
  GetText (MESSAGE_ID_5678, 
     C_Name (1 .. C_Name'Last - 1),
     Error_Type'Image (To_Error (GNAT.OS_Lib.Errno));

The English version of MESSAGE_ID_5678 would be:
  "can't open device %s : %s";

Note that a language that requires different noun/verb ordering can
use this approach quite nicely.

That seems to be a reasonable approach, and my current application
could be incrementally changed to accomodate it.

Anyone that wants to port my application to Spanish then just has to
translate the provided English strings to Spanish.

Ah; it might be that the new language _requires_ a 16 bit character
set (Chinese, for example). Then we have to assume UTF-8 encoding. It
might be simpler if 'raise' supported Wide_String (or
Wide_Wide_String?) directly, but it's not an insurmountable problem.
Perhaps Ada 2015 will allow Wide_Wide_String for exceptions.

> The construction of a message that meets the UI criteria (the parser
> loop with prompt in this case) becomes the job of the a View package
> that matches the display.

The _primary_ role of a parser is to accept user input and provide
feedback on errors. Why is it _better_ to move part of that job over
into the View package?

> - the program points the reader to the software types and
>   modules involved in propagating error information by
>   naming the package and type at both ends (View in this case).
>   A change in the implementation of View won't necessitate
>   a recompilation of Write_Output, unlike using
>   raise ... with ... for message construction.

Anticipating a change in implementation is a good reason for
separating out packages. 

However, I have yet to see an _actual_ implemention of View that is
not equivalent to "write this string to a device". So I do _not_
anticipate changing that implementation.

-- 
-- Stephe



  reply	other threads:[~2007-01-27 18:17 UTC|newest]

Thread overview: 181+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-01-15 13:44 Structured exception information Maciej Sobczak
2007-01-15 17:17 ` claude.simon
2007-01-16  9:04   ` Maciej Sobczak
2007-01-16 22:39     ` Randy Brukardt
2007-01-15 17:28 ` Robert A Duff
2007-01-15 18:29   ` Georg Bauhaus
2007-01-15 19:44     ` Dmitry A. Kazakov
2007-01-15 20:06       ` Georg Bauhaus
2007-01-15 21:56         ` Randy Brukardt
2007-01-15 22:32           ` Robert A Duff
2007-01-16 18:36             ` Ray Blaak
2007-01-16 19:18               ` C# versus Ada (was: Structured exception information) Georg Bauhaus
2007-01-16 23:29                 ` C# versus Ada Markus E Leypold
2007-01-18 10:22                   ` Dmitry A. Kazakov
2007-01-17 18:14                 ` C# versus Ada (was: Structured exception information) Ray Blaak
2007-01-16 23:27               ` Structured exception information Markus E Leypold
2007-01-17  7:28               ` Martin Krischik
2007-01-16 22:36             ` Randy Brukardt
2007-01-17 16:12               ` Bob Spooner
2007-01-17 23:42                 ` Randy Brukardt
2007-01-16  9:11           ` Dmitry A. Kazakov
2007-01-16 10:45             ` Maciej Sobczak
2007-01-16 13:26               ` Dmitry A. Kazakov
2007-01-16 14:44                 ` Maciej Sobczak
2007-01-16 15:15                   ` Dmitry A. Kazakov
2007-01-16 17:50             ` Jeffrey Carter
2007-01-16 18:31               ` Dmitry A. Kazakov
2007-01-16 22:52                 ` Randy Brukardt
2007-01-17  8:58                   ` Dmitry A. Kazakov
2007-01-17 18:38                     ` Jeffrey Carter
2007-01-17 23:18                       ` Randy Brukardt
2007-01-17 23:46                         ` Robert A Duff
2007-01-18  6:34                         ` Jeffrey Carter
2007-01-19  7:34                           ` Randy Brukardt
2007-01-19 13:52                             ` Dmitry A. Kazakov
2007-01-19 18:57                               ` Jeffrey Carter
2007-01-19 19:57                                 ` Robert A Duff
2007-01-20 20:59                                   ` Jeffrey Carter
2007-01-18  9:55                       ` Dmitry A. Kazakov
2007-01-18 18:28                         ` Jeffrey Carter
2007-01-17 23:36                     ` Randy Brukardt
2007-01-18 10:16                       ` Dmitry A. Kazakov
2007-01-15 22:19     ` Robert A Duff
2007-01-16 13:12       ` Georg Bauhaus
2007-01-15 22:42 ` Adam Beneschan
2007-01-15 23:22   ` Robert A Duff
2007-01-16  6:03     ` tmoran
2007-01-16 13:30 ` Stephen Leake
2007-01-16 14:33   ` Maciej Sobczak
2007-01-16 14:45     ` Georg Bauhaus
2007-01-16 17:54     ` Jeffrey Carter
2007-01-16 22:55       ` Randy Brukardt
2007-01-17 12:10     ` Stephen Leake
2007-01-17 14:05       ` Maciej Sobczak
2007-01-19  9:47         ` Stephen Leake
2007-01-19 11:03           ` Dmitry A. Kazakov
2007-01-20 15:04             ` Stephen Leake
2007-01-21 10:40               ` Dmitry A. Kazakov
2007-01-23  7:28                 ` Stephen Leake
2007-01-23 14:21                   ` Dmitry A. Kazakov
2007-01-25  2:39                     ` Stephen Leake
2007-01-19 13:36           ` Maciej Sobczak
2007-01-20 15:33             ` Stephen Leake
2007-01-20 16:33               ` Robert A Duff
2007-01-21 22:42                 ` Stephen Leake
2007-01-21 23:45                   ` Robert A Duff
2007-01-22  9:14                     ` Maciej Sobczak
2007-01-23  7:33                     ` Stephen Leake
2007-01-23 15:07                       ` Robert A Duff
2007-01-23 15:54                         ` Maciej Sobczak
2007-01-23 17:10                           ` Robert A Duff
2007-01-23 23:59                       ` Randy Brukardt
2007-01-22  9:28               ` Maciej Sobczak
2007-01-23  9:46                 ` Stephen Leake
2007-01-23 14:18                   ` Maciej Sobczak
2007-01-25  2:32                     ` Stephen Leake
2007-01-25  8:53                       ` Maciej Sobczak
2007-01-26  9:35                         ` Stephen Leake
2007-01-26 11:16                           ` Markus E Leypold
2007-01-26 13:46                           ` Georg Bauhaus
2007-01-27 18:17                             ` Stephen Leake [this message]
2007-01-28 12:38                               ` Simon Wright
2007-01-28 12:39                               ` Simon Wright
2007-01-28 13:18                               ` Stephen Leake
2007-01-28 15:44                                 ` Georg Bauhaus
2007-01-28 21:48                                 ` Ray Blaak
2007-01-28 18:50                               ` Georg Bauhaus
2007-01-30  2:15                                 ` Stephen Leake
2007-01-31 18:58                                   ` Georg Bauhaus
2007-02-01 12:20                                     ` Stephen Leake
2007-02-01 14:17                                       ` Georg Bauhaus
2007-01-25 21:52                       ` Randy Brukardt
2007-01-24  0:10                   ` Randy Brukardt
2007-01-24 14:17                     ` Wasteful internationalization (Was: Structured exception information) Alex R. Mosteo
2007-01-24 14:49                       ` Dmitry A. Kazakov
2007-01-24 23:48                         ` Wasteful internationalization Björn Persson
2007-01-25  9:45                           ` Markus E Leypold
2007-01-24 21:03                       ` Wasteful internationalization (Was: Structured exception information) Randy Brukardt
2007-01-25 11:17                         ` Alex R. Mosteo
2007-01-25 21:37                           ` Wasteful internationalization Björn Persson
2007-01-25 21:57                           ` Wasteful internationalization (Was: Structured exception information) Randy Brukardt
2007-01-26  9:13                             ` Dmitry A. Kazakov
2007-01-26 12:12                               ` Georg Bauhaus
2007-01-27  4:09                               ` Randy Brukardt
2007-01-27 17:15                             ` Wasteful internationalization Stephen Leake
2007-01-27 20:44                               ` Markus E Leypold
2007-01-28  0:09                                 ` Björn Persson
2007-01-28  1:08                                   ` Björn Persson
2007-01-28 15:21                                     ` Markus E Leypold
2007-01-29  1:23                                       ` Larry Kilgallen
2007-01-29 19:02                                         ` Björn Persson
2007-01-29 20:19                                           ` Larry Kilgallen
2007-02-01  6:23                                             ` Simon Wright
2007-02-03  0:48                                             ` Björn Persson
2007-02-03  1:04                                               ` Adam Beneschan
2007-02-03 11:52                                                 ` Larry Kilgallen
2007-02-03  2:36                                               ` Markus E Leypold
2007-02-03  2:37                                                 ` Markus E Leypold
2007-02-03 19:59                                                 ` Björn Persson
2007-02-03 20:16                                                   ` Markus E Leypold
2007-02-05 19:26                                                     ` Björn Persson
2007-02-04  4:51                                                   ` Alexander E. Kopilovich
2007-02-05 19:27                                                     ` Björn Persson
2007-02-06  1:32                                                   ` Randy Brukardt
2007-02-06  1:54                                                     ` Markus E Leypold
2007-02-07  1:55                                                       ` Björn Persson
2007-02-07  2:20                                                         ` Markus E Leypold
2007-02-12  1:33                                                           ` Björn Persson
2007-02-12  8:16                                                             ` Franz Kruse
2007-02-12  9:20                                                             ` Not at all wasteful internationalization Martin Krischik
2007-02-12 11:08                                                               ` Georg Bauhaus
2007-02-12 13:02                                                                 ` Martin Krischik
2007-02-07 20:39                                                         ` Wasteful internationalization Randy Brukardt
2007-02-08 13:33                                                           ` Stephen Leake
2007-02-12  2:42                                                           ` Björn Persson
2007-02-06 11:01                                                     ` Peter Hermann
2007-02-06 19:02                                                     ` OT: Flash (was: Re: Wasteful internationalization) Jeffrey R. Carter
2007-02-06 19:40                                                       ` OT: Flash Markus E Leypold
2007-02-03 11:51                                               ` Wasteful internationalization Larry Kilgallen
2007-01-29 18:54                                       ` Björn Persson
2007-01-29 19:03                                         ` Markus E Leypold
2007-01-30 17:46                                           ` Georg Bauhaus
2007-01-30 19:37                                             ` Markus E Leypold
2007-01-30 20:43                                               ` Georg Bauhaus
2007-01-30 20:50                                                 ` Georg Bauhaus
2007-01-30 21:54                                                 ` Markus E Leypold
2007-01-31 11:26                                               ` Alex R. Mosteo
2007-01-31 15:17                                                 ` Markus E Leypold
2007-02-03  0:49                                                 ` Björn Persson
2007-02-03 16:05                                                   ` Alex R. Mosteo
2007-02-03  0:48                                               ` Björn Persson
2007-02-01 12:08                                             ` Stephen Leake
2007-02-03  0:49                                               ` Björn Persson
2007-02-03  9:46                                                 ` Dmitry A. Kazakov
2007-02-03 18:48                                                 ` Stephen Leake
2007-02-03 20:27                                                   ` Björn Persson
2007-01-30  2:20                                       ` Stephen Leake
2007-01-30 10:01                         ` Wasteful internationalization (Was: Structured exception information) Harald Korneliussen
2007-01-19 15:45           ` Structured exception information Robert A Duff
2007-01-20 16:08             ` Stephen Leake
2007-01-20 21:59               ` Robert A Duff
2007-01-19 18:14           ` Ray Blaak
2007-01-19 20:07           ` Robert A Duff
2007-01-20 16:16             ` Stephen Leake
2007-01-20 21:20               ` Ray Blaak
2007-01-21 22:34                 ` Stephen Leake
2007-01-20 22:07               ` Robert A Duff
2007-01-21 10:45                 ` Dmitry A. Kazakov
2007-01-21 23:51                   ` Robert A Duff
2007-01-22 14:39                     ` Dmitry A. Kazakov
2007-01-22 19:02                       ` Robert A Duff
2007-01-23 14:23                         ` Dmitry A. Kazakov
2007-01-29  1:30   ` Brian May
2007-01-16 13:30 ` Structured exception information (task, ANEX E) Martin Krischik
2007-01-16 23:07   ` Randy Brukardt
2007-01-19 16:01   ` Robert A Duff
2007-01-22  7:17     ` Martin Krischik
2007-01-22 19:40       ` Robert A Duff
2007-01-16 15:48 ` Structured exception information Alex R. Mosteo
2007-01-16 18:07   ` Jeffrey Carter
2007-01-17  6:38     ` Duncan Sands
replies disabled

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