Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
siddhu Math
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 215
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49432
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic