From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,8af02d07133bfac9 X-Google-Attributes: gid103376,public From: John English Subject: Re: Exception scope and handling Date: 2000/11/13 Message-ID: <3A0FCD45.269A379F@bton.ac.uk>#1/1 X-Deja-AN: 693036939 Content-Transfer-Encoding: 7bit References: <8uo87r$ato$1@nnrp1.deja.com> X-Accept-Language: en Content-Type: text/plain; charset=us-ascii X-Complaints-To: news@bton.ac.uk X-Trace: saturn.bton.ac.uk 974114143 12077 193.62.183.204 (13 Nov 2000 11:15:43 GMT) Organization: University of Brighton Mime-Version: 1.0 NNTP-Posting-Date: 13 Nov 2000 11:15:43 GMT Newsgroups: comp.lang.ada Date: 2000-11-13T11:15:43+00:00 List-Id: 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 -----------------------------------------------------------------