Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Re: variable scope with finally

Reply
Thread Tools

Re: variable scope with finally

 
 
J.W
Guest
Posts: n/a
 
      07-09-2003
I haven't much to add that hasn't already been said...
but one helpful tip to remember is that whenever you create a variable, if
it is not static it will only exist between the opening and closing braces
that enclose it (and of course it's accessible in nested brackets).

The good thing about java is that it's a tad easier to see where a block
starts, since java will not let you create a block simply by using opening
and closing brackets (unlike C or C++), you have to use a statement like if,
while, for, try, catch, finally etc etc...


"Rui Pacheco" <(E-Mail Removed)> wrote in message
news:b54pl3$34h$(E-Mail Removed)...
> I have a simple app:
>
>
> public myclass{
>
> public blah main( String[] args ){
>
> try{
> MyCodeThatThrowsAnException();
>
> SomeObject myInstance = new SomeObject();
> myInstance.itsMethod();
>
> }catch( MyException ){
> System.out.println("Wow, barely caught that exception!");
> }
>
> finally{
> //Final clean up here
> }
> }
> }
>
>
> Well, this is more or less like my app. My problem is, variables that

I
> have initiated inside the try{} block don't seem to exist in the finally.
> This means that if my objects have methods that should be used in the
> cleanup, they can't be accessed in the finally.
> Am I right or am I missing something? If I'm right, how can I reach

the
> methods of the objects that were initiated inside the try block?
>
> Thank you very much
> Rui Pacheco
>
>



 
Reply With Quote
 
 
 
 
Thomas Weidenfeller
Guest
Posts: n/a
 
      07-09-2003
"J.W" <(E-Mail Removed)> writes:
> The good thing about java is that it's a tad easier to see where a block
> starts, since java will not let you create a block simply by using opening
> and closing brackets (unlike C or C++), you have to use a statement like if,
> while, for, try, catch, finally etc etc...


Your claim is simply wrong.

/Thomas
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Having trouble understanding function scope and variable scope Andrew Falanga Javascript 2 11-22-2008 09:23 PM
Try...Catch...Finally not firing finally? David Lozzi ASP .Net 12 05-11-2007 12:41 AM
Scope - do I need two identical classes, each with different scope? ann Java 13 09-13-2005 03:07 AM
IMPORT STATIC; Why is "import static" file scope? Why not class scope? Paul Opal Java 12 10-10-2004 11:01 PM
How do I scope a variable if the variable name contains a variable? David Filmer Perl Misc 19 05-21-2004 03:55 PM



Advertisments