Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception block scope

 
Devendra Walanj
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello I have a code as follows
1. Not working Code :

as you can see fore the the code will not compile

2. Working Code :


As you can see the difference in both the snippets that the placement of the psw object.
So want to know that when I created the PrintWriter object in the try block it's scope got limited it try block only.

Does this mean that object / variables defined in try block have their scope limit to that try block ?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64715
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. As with every other block. Why would try be different?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic