comp.lang.ada
 help / color / mirror / Atom feed
From: John English <je@bton.ac.uk>
Subject: Re: Exception scope and handling
Date: 2000/11/13
Date: 2000-11-13T11:15:43+00:00	[thread overview]
Message-ID: <3A0FCD45.269A379F@bton.ac.uk> (raw)
In-Reply-To: 8uo87r$ato$1@nnrp1.deja.com

Sandro Binetti wrote:
> Suppose to declarate an exception inside the declarative region of a
> procedure, and handle it at the end of the body of the procedure.
> What's the meaning of re-raising this exception outside this body?
> 
> Take a simple example:
> 
> procedure PROC1 is
> 
>   procedure PROC2 is
>     FOO:EXCEPTION;
>   begin
>     ....
>     ....
>   EXCEPTION
>     when FOO => handle_it;
>                 raise; -- ???? what's the meaning of this
>   end proc2;
> 
> begin
>   ...
>   ...
>   ...
>   -- what kind of object is FOO here?
> EXCEPTION
>   when others => -- ???? why coul'd I handle FOO here, even if I don't
>                  -- know anything about it?
> end proc1;

"Raise" on its own re-raises the same exception (FOO in this case).
The exception propagates out of proc2 and is caught by the exception
handler in proc1, but the name FOO ceased to exist 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
-----------------------------------------------------------------




  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 [this message]
2000-11-13  0:00   ` Robert Dewar
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