comp.lang.ada
 help / color / mirror / Atom feed
From: tmoran@acm.org
Subject: Re: Error-names.
Date: Sun, 29 Feb 2004 23:43:21 GMT
Date: 2004-02-29T23:43:21+00:00	[thread overview]
Message-ID: <tOu0c.11106$PR3.246776@attbi_s03> (raw)
In-Reply-To: vtu9h1-kq7.ln1@martinkl.dialup.fu-berlin.de

>   function Get_Error_Code (E : Exception_Occurrence) return C_Integer is
>   begin
>       if Exception_Identity (E) = Program_Error'Identity then
>           return Program_Error_Code;
>       elsif Exception_Identity (E) = Constraint_Error'Identity then
>           return Constraint_Error_Code;
>       elsif ...
  "Use the Force, Luke", or more specifically, Let the Ada compiler
help you find and eliminate errors.

  It would not be hard to leave out, or have multiple uses of, an error
code, as in:
    Constraint_Error_Code : constant Exception_Codes := -10;
    Program_Error_Code    : constant Exception_Codes := -9;
    Storage_Error_Code    : constant Exception_Codes := -9;
    Status_Error_Code     : constant Exception_Codes := -7;
    My_Special_Error_Code : constant Exception_Codes := -5;
    ...
Similarly, a new exception might be added, but someone forgets to
add it to the if-elsif list.

With the if-elsif style you can only hope that neither of those happens.
But if you do

    Coded_Exception_List : constant array(Exception_Codes)
    of Ada.Exceptions.Exception_ID
      := (Constraint_Error_Code => Constraint_Error'Identity,
          Program_Error_Code    => Program_Error'Identity,
          Storage_Error_Code    => Storage_Error'Identity,
          IO_Status_Error_Code  => Ada.IO_Exceptions.Status_Error'Identity,
          My_Special_Error_Code => My_Special_Exception'Identity,
          ...
then the compiler will warn you if two of your error codes are the
same, or if you've left any out in the Exception_Codes range.
  It also has the (possible) advantage that you can trivially translate
a code back into an exception:
  Ada.Exceptions.Raise_Exception(Coded_Exception_List(Code), Message);



  reply	other threads:[~2004-02-29 23:43 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-02-28 12:58 Error-names Martin Klaiber
2004-02-28 13:35 ` Error-names Martin Dowie
2004-02-28 15:26   ` Error-names Martin Klaiber
2004-02-28 17:19     ` Error-names Marius Amado Alves
2004-02-28 18:31       ` Error-names Martin Klaiber
2004-02-28 19:47         ` Error-names tmoran
2004-02-28 20:29           ` Error-names Martin Klaiber
2004-02-29 19:03           ` Error-names Jeffrey Carter
2004-02-29 20:04             ` Error-names tmoran
2004-02-29 23:24               ` Error-names Björn Persson
2004-03-01 11:29                 ` Error-names Martin Klaiber
2004-03-01 12:48                   ` Error-names Marius Amado Alves
2004-03-02  2:15                     ` Error-names Jeffrey Carter
2004-02-29 20:33             ` Error-names Martin Klaiber
2004-02-29 23:43               ` tmoran [this message]
2004-03-01 11:20                 ` Error-names Martin Klaiber
2004-03-07 15:10                   ` Error-names Björn Persson
2004-03-08  5:42                   ` Error-names Dave Thompson
2004-02-28 20:26         ` Error-names Jacob Sparre Andersen
2004-02-28 18:29 ` Error-names Alexandre E. Kopilovitch
2004-02-29  5:30 ` Error-names David Marceau
2004-02-29 12:17   ` Error-names Martin Klaiber
2004-02-29 19:56     ` Error-names David Marceau
2004-02-29 21:57       ` Error-names Martin Klaiber
2004-03-01 23:20       ` Error-names Randy Brukardt
replies disabled

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