comp.lang.ada
 help / color / mirror / Atom feed
From: Jacob Sparre Andersen <sparre@nbi.dk>
Subject: Re: Error-names.
Date: 28 Feb 2004 21:26:20 +0100
Date: 2004-02-28T21:26:20+01:00	[thread overview]
Message-ID: <plznb354sz.fsf@sparre.crs4.it> (raw)
In-Reply-To: sd37h1-5n4.ln1@martinkl.dialup.fu-berlin.de

Martin Klaiber wrote:
> Marius Amado Alves <amado.alves@netcabo.pt> wrote:

> > function Main return Error_Code_Type is
> >  -- exception-raising calls here
> > exception
> >  when E : others => return Error_Code_Of (E);
> > end;
> 
> > Now you only have to implement Error_Code_Of.
> 
> > (Ain't top-down design great? ;-)
> 
> > The 'trick' you could be missing is the "E : others" construct
> > above. E is the exception occurence. From it you can go to the
> > exception name. See package Ada.Exceptions--or, better yet,
> > section 11.4 of the ARM.
> 
> Well, if I understand it right, I still have to distinguish between
> the different exceptions before I call Error_Code_Of, is this right?

No.  E is like a renaming of whatever exception actually was raised.

> Like this (assume I have 5 exceptions A to E):
> 
>   function Main return Error_Code_Type is
>    -- exception-raising calls here
>   exception
>    when A : others => return Error_Code_Of (A);
>    when B : others => return Error_Code_Of (B);
>    when C : others => return Error_Code_Of (C);
>    when D : others => return Error_Code_Of (D);
>    when E : others => return Error_Code_Of (E);
>   end;

No, that wouldn't work.  Just:

   [...]
   exception
      when Raised_Exception : others =>
         return Error_Code_Of (Raised_Exception);
   end;

If the exception raised is A, then Ada.Exceptions.Exception_Name
(Raised_Exception) will return the string "A" (or however it is that
the compiler names the exception you call A.

Read the suggested part of the reference manual.

Jacob
-- 
"We will be restoring normality as soon as we are sure what is normal anyway."



  parent reply	other threads:[~2004-02-28 20:26 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               ` Error-names tmoran
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         ` Jacob Sparre Andersen [this message]
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