Re: Re: variable scope question

David Bernard <[email protected]> Thu, 07 Jul 2005 12:38:11 +0200
Newsgroups gmane.comp.lang.nice.general
Message-ID <[email protected]>
Daniel Bonniot wrote:

> David Bernard wrote:
>
>> If a variable is declared in a try clause (directly under the try), 
>> is like in java, the variable is out of the scope of the catch or 
>> finally clause ? (Note : in the user manual there is nothing about 
>> Exception management).
>>
>> It should be "nice" if try/catch/finally share the same variable scope :
>
>
>> void doSomeThing() {
>>  try {
>>    var out = new ....
>>    ....
>>  } catch(IOException exc) {
>>    ...
>>  } finally {
>>    if (out != null) {
>
>
> I don't think that's possible, because the expression assigned to the 
> variable might throw an exception, in which case the assignment did 
> not happen, and the variable has no value.
>
> Maybe you wanted the variable to be null in that case. That might be 
> possible, but isn't it an abuse of null, being completely implicit? 
> I'm afraid it would be confusing with the case where the assignment 
> happened and the value was null. It would also be tricky to implement 
> it efficiently with primitive types.

My suggestion is to delegete to the compiler to declare 'out' in the 
parent scope of try and set the variable to null.
About the "if (out != null)" if only to avoid NPE in java, but the 
method close(OutputStream v) (in nice) could be change to 
close(?OutputStream v) .... => new question is possible in nice to 
overwrite a method foo(Bar v) with foo(?Bar v) ?

Other solution avec a method undef(v) to check if a variable is declared 
(or null).

>
> > (Note : in the user manual there is nothing about Exception management)
>
> Indeed, this is missing. Basically it is the same as Java, except that 
> there are no throws clauses.
>
> I added a note in 
> http://nice.sf.net/cgi-bin/twiki/view/Dev/UserManualOmissions


May be a wiki version of the UserManual could be used.



-------------------------------------------------------
SF.Net email is sponsored by: Discover Easy Linux Migration Strategies
from IBM. Find simple to follow Roadmaps, straightforward articles,
informative Webcasts and more! Get everything you need to get up to
speed, fast. http://ads.osdn.com/?ad_id=7477&alloc_id=16492&op=click