This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Local variable initialization error

 
ujjawal rohra
Ranch Hand
Posts: 105
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Why is the compiler complaining at lines 2 and 3 that x is not initilized when it gets tha value 42 at line 1 ? ?
 
Sebastian Janisch
Ranch Hand
Posts: 1183
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
because it refers to it's declaration 'int x'. Who ensures that the try block will ever run to completion and assign a value to x ?

So, initialize the int upon declaration.
 
Harpreet Singh janda
Ranch Hand
Posts: 317
Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try -catch signify that there could be an exception, means we are not sure whether the particular line of code in try-catch will execute or not. So for compiler it is not sure that whether the line which is initializing the variable x will run or not and hence throws an exception.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic