comp.lang.ada
 help / color / mirror / Atom feed
From: Robert Dewar <robert_dewar@my-deja.com>
Subject: Re: Exception scope and handling
Date: 2000/11/13
Date: 2000-11-13T00:00:00+00:00	[thread overview]
Message-ID: <8uonsd$mm1$1@nnrp1.deja.com> (raw)
In-Reply-To: 3A0FCD45.269A379F@bton.ac.uk

In article <3A0FCD45.269A379F@bton.ac.uk>,
  John English <je@bton.ac.uk> wrote:
> The exception propagates out of proc2 and is caught by the
> exception handler in proc1, but the name FOO ceased to exist.

Well this is a little misleading, the comment from Des is a
bit clearer here. Exceptions are not like variables. When you
leave the scope of a procedure, a local variable is really
really gone.

But exceptions are global objects, unlike a variable in the
recursive case, where there is one variable for each level,
in the case of an exception declared in a recursive procedure,
there is only one for all levels (it's a bit similar to an
"own" variable in Algol-60, or a static variable in C).

So when you leave the procedure, the name temporarily goes
out of scope, but for example, if the caller gets the exception
occurrence, stashes it away, and later calls the original
procedure passing in this exception occurrence, then the
exception can be handled by name even without needing
recursion.

Yes, you can't handle it by name if it's not visible at the
point of the caller, but that's just a normal visibility rule.



on exit from proc2,
> so when you catch it in proc1's exception handler you can no

longer
> refer to it by name (so you can't say "when FOO", you have to

say
> "when others"). The fact that an exception's name may be lost

to
> view doesn't mean that an active instance of the exception

itself
> will go away when the name does -- exceptions don't go away

until
> they're caught and handled.
>
> It's usually a good idea NOT to declare exceptions in nested

scopes
> for this very reason.
>
> HTH,
>
>

----------------------------------------------------------------

-
>  John English              | mailto:je@brighton.ac.uk
>  Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
>  Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS

**
>  University of Brighton    |    -- see http://burks.bton.ac.uk
>

----------------------------------------------------------------

-
>


Sent via Deja.com http://www.deja.com/
Before you buy.




  reply	other threads:[~2000-11-13  0:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-11-13  0:00 Exception scope and handling Sandro Binetti
2000-11-13  0:00 ` John English
2000-11-13  0:00   ` Robert Dewar [this message]
2000-11-13  0:00 ` des walker
replies disabled

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