This week's book giveaway is in the Big Data forum.
We're giving away four copies of Elasticsearch in Action and have Radu Gheorghe & Matthew Lee Hinman on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes try statement variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Elasticsearch in Action this week in the Big Data forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "try statement variables" Watch "try statement variables" New topic

try statement variables

Eric Giblock

Joined: Nov 19, 2003
Posts: 4
int variable 1
int variable 2.

how can i access the values of the variables inside the try statement from outside the try statement??

-- Eric
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24189

Hi Eric,

You can't. You can move the declarations outside the try block:

Note that you may have to initialize the variables when they're declared, or the compiler may complain that the variables "may not have been initialized" when you access them in the catch block.

[Jess in Action][AskingGoodQuestions]
subject: try statement variables