comp.lang.ada
 help / color / mirror / Atom feed
From: seas.gwu.edu!mfeldman@uunet.uu.net  (Michael Feldman)
Subject: Re: Exceptions in Declarative Region
Date: 13 Aug 93 03:23:21 GMT	[thread overview]
Message-ID: <1993Aug13.032321.21214@seas.gwu.edu> (raw)

In article <1993Aug12.185359.6400@iplmail.orl.mmc.com> rgilbert@orl.mmc.com wri
tes:
>The LRM (11-4.2a) specifies that exceptions that occur in the
>decarative portion are propagated up to the calling procedure
>and not handled by the current function's exception handler.
>
>Can somebody provide the rationale for this?  Why shouldn't the
>exception handler for a procedure/function not include the
>declarative portion?
>
Hey! A technical question!

The difficulty arises because if an exception is raised in elaborating
a declaration, there usually are declarations below that one that have
not been elaborated yet. Consider:

PROCEDURE Foo IS
   . . .
    Y: Float := some negative value
    X: Float := Math.Sqrt(Y);
    Z: Float;
   . . .

BEGIN

   . . .

EXCEPTION

   . . .

  WHEN Invalid_Argument_to_Sqrt =>   -- or some such exception
    Do_something_involving_Z;
   . . .

END Foo;

See the problem? Z doesn't exist at the time the exception is raised.
Since declarations aren't elaborated till runtime (thinking of a
suborogram whose locals don;t exist on the stack till the subprogram
is called at runtime), and are elaborated in order of occurrence 
(how else?), there's no way an exception handler could trap such an
exception - its context doesn't completely exist. This would take a
bad situation and make it worse.

BTW - using an as-yet unelaborated variable results in (what else?)
an exception being raised, generally Program_Error. So we go out of
the frying pan into the fire.

My bottom line in teaching is that initializations and other dynamic
things in declarations are neat, but one has to use them with great
care because they wreak havoc with one's exception propagation and
handling strategy. No free lunch, as usual...

Hope this helps.

Mike Feldman
------------------------------------------------------------------------
Michael B. Feldman -  co-chair, SIGAda Education Committee
Professor, Dept. of Electrical Engineering and Computer Science
The George Washington University -  Washington, DC 20052 USA
202-994-5253 (voice) - 202-994-0227 (fax) - mfeldman@seas.gwu.edu (Internet)
"We just changed our CONFIG.SYS, then pressed CTRL-ALT-DEL. It was easy."
-- Alexandre Giglavyi, director Lyceum of Information Technologies, Moscow.
------------------------------------------------------------------------

             reply	other threads:[~1993-08-13  3:23 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1993-08-13  3:23 Michael Feldman [this message]
  -- strict thread matches above, loose matches on Subject: below --
1993-08-16 12:22 Exceptions in Declarative Region Wes Groleau x1240 C73-8
1993-08-13  4:16 cis.ohio-state.edu!magnus.acs.ohio-state.edu!math.ohio-state.edu!sdd.hp.c
1993-08-13  3:49 Michael Feldman
1993-08-13  3:27 Michael Feldman
1993-08-13  2:49 Dave Bashford
1993-08-12 23:02 Mark A Biggar
1993-08-12 22:58 Mark A Biggar
1993-08-12 22:34 Dave Bashford
1993-08-12 18:53 agate!howland.reston.ans.net!vixen.cso.uiuc.edu!sdd.hp.com!col.hp.com!csn
replies disabled

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