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, MSGID_RANDY 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: Robert Dewar Subject: Re: Exception scope and handling Date: 2000/11/13 Message-ID: <8uonsd$mm1$1@nnrp1.deja.com>#1/1 X-Deja-AN: 693041972 References: <8uo87r$ato$1@nnrp1.deja.com> <3A0FCD45.269A379F@bton.ac.uk> X-Http-Proxy: 1.0 x64.deja.com:80 (Squid/1.1.22) for client 205.232.38.240 Organization: Deja.com - Before you buy. X-Article-Creation-Date: Mon Nov 13 12:47:10 2000 GMT X-MyDeja-Info: XMYDJUIDrobert_dewar Newsgroups: comp.lang.ada X-Http-User-Agent: Mozilla/4.61 [en] (OS/2; I) Date: 2000-11-13T00:00:00+00:00 List-Id: In article <3A0FCD45.269A379F@bton.ac.uk>, John English 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.