comp.lang.ada
 help / color / mirror / Atom feed
* Array of exception
@ 2001-10-02  8:50 Lutz Donnerhacke
  2001-10-02 11:02 ` maa
  0 siblings, 1 reply; 6+ messages in thread
From: Lutz Donnerhacke @ 2001-10-02  8:50 UTC (permalink / raw)


Is it possible to define an array of exceptions? I do not get it.
(subtype required)

Currently I have a list of inband-signaling-codes catched by a long case:
  case res in
     when -1 => raise EXXX;
     when -2 => raise EYYY;
     ...
  end case;

I'd like to write:
  raise myexception (res);
exception
  when Constraint_Error => return res;



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Array of exception
  2001-10-02 11:02 ` maa
@ 2001-10-02 10:13   ` Lutz Donnerhacke
  2001-10-02 20:23     ` tmoran
  0 siblings, 1 reply; 6+ messages in thread
From: Lutz Donnerhacke @ 2001-10-02 10:13 UTC (permalink / raw)


* maa@liacc.up.pt wrote:
>Quoting Lutz Donnerhacke <lutz@iks-jena.de>:
>> Is it possible to define an array of exceptions? I do not get it.
>> (subtype required)
>
>Package Ada.Exceptions provides "regular" types associated with exceptions
>viz. Exception_Id and Exception_Occurrence.  Attribute 'Identity gives the
>Id of an exception.

Yep. Known and didn't remembered last evening. In the meantime the problem
changed slightly, because the inband signaling range is not continious. *GNA*
Using Exception_Id and Raise_Expression require me to rewrite the whole CASE
into an explicit array so I do not shorten the source code anyway. Only the
produced asm code can be modified by moving the jump table into the data
segment. *Hmm*



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Array of exception
  2001-10-02  8:50 Array of exception Lutz Donnerhacke
@ 2001-10-02 11:02 ` maa
  2001-10-02 10:13   ` Lutz Donnerhacke
  0 siblings, 1 reply; 6+ messages in thread
From: maa @ 2001-10-02 11:02 UTC (permalink / raw)
  To: comp.lang.ada

Quoting Lutz Donnerhacke <lutz@iks-jena.de>:
> Is it possible to define an array of exceptions? I do not get it.
> (subtype required)
> . . .

Package Ada.Exceptions provides "regular" types associated with exceptions viz.
Exception_Id and Exception_Occurrence.  Attribute 'Identity gives the Id of an
exception.  [Ben-Ari 1998, 11.2] shows how to save and reraise exceptions, using
Exception_Occurence_Access (in a priority queue).

[Ben-Ari 1998]
  Ada for Software Engineers / M. Ben-Ari.
  John Wiley & Sons, 1998.
  425 p.

Cheers,

--MAA


-------------------------------------------------
This mail sent through IMP: webmail.niaad.liacc.up.pt



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Array of exception
  2001-10-02 10:13   ` Lutz Donnerhacke
@ 2001-10-02 20:23     ` tmoran
  2001-10-03 16:25       ` Darren New
  2001-10-04  8:53       ` Lutz Donnerhacke
  0 siblings, 2 replies; 6+ messages in thread
From: tmoran @ 2001-10-02 20:23 UTC (permalink / raw)


>     when -1 => raise EXXX;
>     when -2 => raise EYYY;
>     ...
>Using Exception_Id and Raise_Expression require me to rewrite the whole CASE
>into an explicit array so I do not shorten the source code anyway. Only the
  Clarify please.  It appears that somewhere you need to establish the
relation between, eg, -2 and EYYY.  Is
   case res is
      when -1 => raise EXXX;
      when -2 => raise EYYY;
      ...
preferable to
   jump : constant array(...) of Exception_ID :=
     (-1 => EXXX'Identity,
      -2 => EYYY'Identity,
      ...
Of course one always wonders if a jump table is the best approach for the
problem at hand.



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Array of exception
  2001-10-02 20:23     ` tmoran
@ 2001-10-03 16:25       ` Darren New
  2001-10-04  8:53       ` Lutz Donnerhacke
  1 sibling, 0 replies; 6+ messages in thread
From: Darren New @ 2001-10-03 16:25 UTC (permalink / raw)


tmoran@acm.org wrote:
> 
> >     when -1 => raise EXXX;
> >     when -2 => raise EYYY;
> >     ...
> >Using Exception_Id and Raise_Expression require me to rewrite the whole CASE
> >into an explicit array so I do not shorten the source code anyway. Only the
>   Clarify please.  It appears that somewhere you need to establish the
> relation between, eg, -2 and EYYY.  Is

Coming from an interpreted-language background, the first thing that
jumped to my mind was to name everything like

  EXXX_1 : exception;
  EYYY_2 : exception;
  EZZZ_3 : exception;

Then get the names of the exceptions, parse for the final underline,
convert to an integer, and away you go.

That's probably not very Ada tho. ;-)

-- 
Darren New 
San Diego, CA, USA (PST). Cryptokeys on demand.
                   Who is this Dr. Ibid anyway, 
                  and how does he know so much?



^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Array of exception
  2001-10-02 20:23     ` tmoran
  2001-10-03 16:25       ` Darren New
@ 2001-10-04  8:53       ` Lutz Donnerhacke
  1 sibling, 0 replies; 6+ messages in thread
From: Lutz Donnerhacke @ 2001-10-04  8:53 UTC (permalink / raw)


* tmoran@acm.org wrote:
>>     when -1 => raise EXXX;
>>     when -2 => raise EYYY;
>>     ...
>>Using Exception_Id and Raise_Expression require me to rewrite the whole CASE
>>into an explicit array so I do not shorten the source code anyway.
>
>Clarify please.  It appears that somewhere you need to establish the
>relation between, eg, -2 and EYYY.

Trivial: I'd tried
  type extract_inband_exception_t is array(Positive) of exception;
  extract_inband_exception : constant extract_inband_exception_t := (
     EXXX, EYYY, ... );
in order to instanciate the list of exceptions and there order at once.

>Is
>   case res is
>      when -1 => raise EXXX;
>      when -2 => raise EYYY;
>      ...
>preferable to
>   jump : constant array(...) of Exception_ID :=
>     (-1 => EXXX'Identity,
>      -2 => EYYY'Identity,
>      ...

Yep. The case generates faster code for the normal return value case. ;-)




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2001-10-04  8:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-10-02  8:50 Array of exception Lutz Donnerhacke
2001-10-02 11:02 ` maa
2001-10-02 10:13   ` Lutz Donnerhacke
2001-10-02 20:23     ` tmoran
2001-10-03 16:25       ` Darren New
2001-10-04  8:53       ` Lutz Donnerhacke

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