File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "try statement variables" Watch "try statement variables" New topic
Author

try statement variables

Eric Giblock
Greenhorn

Joined: Nov 19, 2003
Posts: 4
try
{
.....
int variable 1
int variable 2.
}
catch
{}




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
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

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]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: try statement variables