From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 13 Aug 93 03:23:21 GMT From: seas.gwu.edu!mfeldman@uunet.uu.net (Michael Feldman) Subject: Re: Exceptions in Declarative Region Message-ID: <1993Aug13.032321.21214@seas.gwu.edu> List-Id: 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. ------------------------------------------------------------------------