comp.lang.ada
 help / color / mirror / Atom feed
* Exceptions in Declarative Region
@ 1993-08-12 18:53 agate!howland.reston.ans.net!vixen.cso.uiuc.edu!sdd.hp.com!col.hp.com!csn
  0 siblings, 0 replies; 10+ messages in thread
From: agate!howland.reston.ans.net!vixen.cso.uiuc.edu!sdd.hp.com!col.hp.com!csn @ 1993-08-12 18:53 UTC (permalink / raw)


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?

                           Bob 

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

* Re: Exceptions in Declarative Region
@ 1993-08-12 22:34 Dave Bashford
  0 siblings, 0 replies; 10+ messages in thread
From: Dave Bashford @ 1993-08-12 22:34 UTC (permalink / raw)


In article ... rgilbert@orl.mmc.com writes:
>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?
>
>                           Bob 

And a related question: How does a program handle exceptions raised
in the elaboration of global packages and main procedures ?
-- 

db
bashford@srs.loral.com (Dave Bashford, Sunnyvale, CA)

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

* Re: Exceptions in Declarative Region
@ 1993-08-12 22:58 Mark A Biggar
  0 siblings, 0 replies; 10+ messages in thread
From: Mark A Biggar @ 1993-08-12 22:58 UTC (permalink / 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?

Because, in general, there is not much that you can do in the
procedure's handler that's useful, except re-raise the exception.  Yes,
you can contrive cases where it might be useful, but they almost never
occure in real programs.  Besides, no visible effects on the outside
world can have happened yet.  OUT and IN-OUT parameters and global
variables have yet to be touched (except in the pathological case of
a function called as an initializer that modifies global variables,
which is pretty poor programming practice anyway and should be
discouraged strongly.)  Also, any exception raised in the declarative
part prevents any tasks declared or created in the declarative part
from even starting (remember tasks are started up just before the first
statement and after the whole declarative part is done), so no task
clean up is needed either.

--
Mark Biggar
mab@wdl.loral.com

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

* Re: Exceptions in Declarative Region
@ 1993-08-12 23:02 Mark A Biggar
  0 siblings, 0 replies; 10+ messages in thread
From: Mark A Biggar @ 1993-08-12 23:02 UTC (permalink / raw)


In article <1993Aug12.223413.20295@scf.loral.com> bashford@scf.loral.com (Dave 
Bashford) writes:
>And a related question: How does a program handle exceptions raised
>in the elaboration of global packages and main procedures ?

The same way it handles any exception that is not handled by any handler.

--
Mark Biggar
mab@wdl.loral.com

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

* Re: Exceptions in Declarative Region
@ 1993-08-13  2:49 Dave Bashford
  0 siblings, 0 replies; 10+ messages in thread
From: Dave Bashford @ 1993-08-13  2:49 UTC (permalink / raw)


In article ... mab@dst17.wdl.loral.com (Mark A Biggar) writes:
>In article ... bashford@scf.loral.com (Dave Bashford) writes:
>>And a related question: How does a program handle exceptions raised
>>in the elaboration of global packages and main procedures ?
>
>The same way it handles any exception that is not handled by any handler.
>

Perhaps I wasn't clear. My question was:

If an exception occurs in the elaboration of a global package or the 
declaritive part of a main subprogram, there doesn't appear to be any
way for the program to catch the exception and the user will get the
cryptic and probably useless error message generated by the Ada runtime
kernal. Is this true or am I missing something ?
-- 

db
bashford@srs.loral.com (Dave Bashford, Sunnyvale, CA)

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

* Re: Exceptions in Declarative Region
@ 1993-08-13  3:23 Michael Feldman
  0 siblings, 0 replies; 10+ messages in thread
From: Michael Feldman @ 1993-08-13  3:23 UTC (permalink / 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.
------------------------------------------------------------------------

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

* Re: Exceptions in Declarative Region
@ 1993-08-13  3:27 Michael Feldman
  0 siblings, 0 replies; 10+ messages in thread
From: Michael Feldman @ 1993-08-13  3:27 UTC (permalink / raw)


In article <1993Aug12.223413.20295@scf.loral.com> bashford@scf.loral.com (Dave 
Bashford) writes:
>In article ... rgilbert@orl.mmc.com writes:
>>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?
>>
>>                           Bob 
>
>And a related question: How does a program handle exceptions raised
>in the elaboration of global packages and main procedures ?

It doesn't and can't. The LRM is quite clear on this one: "the main
program is abandoned," i.e. crashes. How can Main even get started if
the context created by its own declarations and the packages its WITHs
can't be set up? Better to just crash Main. The alternative is much worse.

I doubt that any language with a block structure could do better.

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.
------------------------------------------------------------------------

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

* Re: Exceptions in Declarative Region
@ 1993-08-13  3:49 Michael Feldman
  0 siblings, 0 replies; 10+ messages in thread
From: Michael Feldman @ 1993-08-13  3:49 UTC (permalink / raw)


In article <1993Aug13.024920.22726@scf.loral.com> bashford@srs.loral.com (Dave 
Bashford) writes:

[deletia]
>
>Perhaps I wasn't clear. My question was:
>
>If an exception occurs in the elaboration of a global package or the 
>declaritive part of a main subprogram, there doesn't appear to be any
>way for the program to catch the exception and the user will get the
>cryptic and probably useless error message generated by the Ada runtime
>kernal. Is this true or am I missing something ?

Yes, it's true. No, you're not missing anything. See a couple of others
posts of mine this evening, in which I try to explain why it's so and 
couldn't be otherwise.

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.
------------------------------------------------------------------------

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

* Re: Exceptions in Declarative Region
@ 1993-08-13  4:16 cis.ohio-state.edu!magnus.acs.ohio-state.edu!math.ohio-state.edu!sdd.hp.c
  0 siblings, 0 replies; 10+ messages in thread
From: cis.ohio-state.edu!magnus.acs.ohio-state.edu!math.ohio-state.edu!sdd.hp.c @ 1993-08-13  4:16 UTC (permalink / raw)


In article <1993Aug13.024920.22726@scf.loral.com> bashford@srs.loral.com (Dave 
Bashford) writes:
>In article ... mab@dst17.wdl.loral.com (Mark A Biggar) writes:
>If an exception occurs in the elaboration of a global package or the 
>declaritive part of a main subprogram, there doesn't appear to be any
>way for the program to catch the exception and the user will get the
>cryptic and probably useless error message generated by the Ada runtime
>kernal. Is this true or am I missing something ?

Basically, this is true.  When an exception is raised in the elaboration
of any of those areas, the execution is not yet in any scope that you can
define an exception handler, so they will propogate to the run time without
getting caught.

There is no way out of this.  As was pointed out earlier, if an exception
is raised here, the state of the program is too "out of control" to have
any real meaningful things to handle.

The error message should not be too obscure.  Such a situation should be
discovered during testing, and the compiler (at least the ones I've used)
will give you the location of the exception.




-- 
Mark Atwood                  | My school and employer have too many problems
matwood@peruvian.cs.utah.edu | without being blamed for mine.

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

* Re: Exceptions in Declarative Region
@ 1993-08-16 12:22 Wes Groleau x1240 C73-8
  0 siblings, 0 replies; 10+ messages in thread
From: Wes Groleau x1240 C73-8 @ 1993-08-16 12:22 UTC (permalink / raw)


In article <1993Aug13.024920.22726@scf.loral.com> bashford@srs.loral.com (Dave 
Bashford) writes:
>If an exception occurs in the elaboration of a global package or the 
>declaritive part of a main subprogram, there doesn't appear to be any
>way for the program to catch the exception and the user will get the
>cryptic and probably useless error message generated by the Ada runtime
>kernal. Is this true or am I missing something ?

It's true.  However, if that is unacceptable, and if your interactive debugger
doesn't help, try this:

with MAIN_PROGRAM;
procedure EXCEPTION_HANDLER is
  -- nothing here to raise an exception...
begin
   MAIN_PROGRAM;
exception
   when -- you fill in the rest
end EXCEPTION_HANDLER;

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

end of thread, other threads:[~1993-08-16 12:22 UTC | newest]

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

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