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 nesting trys and catches Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "nesting trys and catches" Watch "nesting trys and catches" New topic
Author

nesting trys and catches

Joe Panully
Greenhorn

Joined: Oct 10, 2004
Posts: 22
I'm trying to nest some try statements and im erroring with it saying that it's not picking up the catches. I know this is probably a simple bug but could someone please help me, thx.

[ November 18, 2004: Message edited by: Joe Panully ]
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18113
    
  39

The catch must follow the try it is catching from....



Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24166
    
  30

Hi Joe,

What you've done is exceedingly creative, but unforunately, it's wrong.
Instead of separating all the trys into one pile, and the catches into another pile, each "catch" has to immediately follow its "try", like



Here you see one "top-level" try/catch, with one more try/catch nested inside its try block, and another nested inside its catch block.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: nesting trys and catches
 
Similar Threads
Tokens
Problem with echo server and client.
Re: FileWriter write operation
tokenizer throwing NullPointerException
Function of close() and flush() methods..