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 how can i resume to the next instruction when my previous instruction raised excption Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "how can i resume to the next instruction when my previous instruction raised excption" Watch "how can i resume to the next instruction when my previous instruction raised excption" New topic
Author

how can i resume to the next instruction when my previous instruction raised excption

siddhu Math
Ranch Hand

Joined: Aug 10, 2006
Posts: 46
hi

i have a condition say i am doing i/o operation and i did not get the file at the path specified and the whole code is in a try catch block.when i execute an exception is raised then the catch block gets executed and the process terminates.

now what my question is i do not want the process to be terminated i want it again to execute the method which threw that exception.


---------------
Balasubramanian Chandrasekaran
Ranch Hand

Joined: Nov 28, 2007
Posts: 215

You have to check that condition yourself using methods in the File API before performing any operation over file. You can use
exists() method to achieve this.
If you get a negative result then you can code it to repeat the same sequence how many times you need.

There is nothing you can do in case of Try - Catch.Once exception is caught then the program is tend to terminate.
[ January 10, 2008: Message edited by: Balasubramanian Chandrasekaran ]
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
Do you have control over the client which executes the I/O method? If so, the client can handle the exception and do something like prompt the user to reinput the filename and resubmit the request.


SCJP 1.4, SCWCD 1.3, SCBCD 1.3
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37874
    
  22
You could put your try block inside a loop, like thisSomething I just knocked up in a minute, risk of its returning a zero-length List if anything goes wrong, or a zero-length String as the last element, but it gives an opportunity of repeating the reading if there is an Exception.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: how can i resume to the next instruction when my previous instruction raised excption
 
Similar Threads
deadlock situation
try catch and finally blocks
try,catch and finally blocks
Try,Catch & Throw
try catch and finally blocks