Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Local Variable Scope

 
Craig Oliver
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From what I understand:
Local (method) variables can be declared anywhere in code of method.
They are then available for rest of method.

Question is:
If local variable is declared within try/catch exception block is scope of this variable only within try/catch block or entire method from then on?
 
Vicken Karaoghlanian
Ranch Hand
Posts: 522
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can refer to (�14.4.2) for more information about the scope of local variables.
 
Babar Qadri
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Only within try/catch block. And refer the link given by Vicken.
cheers.
 
Mike Gershman
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The key word is block.

Variables declared within a block { ... } are only known within that block.
The individual try, catch, and finally blocks are examples of this.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic