Re: variable scope question

Daniel Bonniot <[email protected]> Thu, 07 Jul 2005 12:08:43 +0200
Newsgroups gmane.comp.lang.nice.general
Message-ID <[email protected]>
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.

 > (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

Daniel



-------------------------------------------------------
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