| Author |
Exception handling
|
Harjit Singh
Ranch Hand
Joined: Feb 01, 2007
Posts: 77
|
|
Hi there, I have a situation where I have a for loop and I'm processing some files from a list in it. I need to continue processing files even if there is a exception. How can I do that. Is there a better way to do that Thanks - Harjit
|
 |
Devesh H Rao
Ranch Hand
Joined: Feb 09, 2002
Posts: 687
|
|
Originally posted by Harjit Singh: Hi there, I have a situation where I have a for loop and I'm processing some files from a list in it. I need to continue processing files even if there is a exception. How can I do that. Is there a better way to do that Thanks - Harjit
Do not know if I got you right but you can do this... Is this what you were looking for...?
|
 |
Kaydell Leavitt
Ranch Hand
Joined: Nov 18, 2006
Posts: 679
|
|
... I agree, but want to add that you may also want a "finally" block. For example, you probably want to always try to close() the File object. Kaydell
|
 |
Harjit Singh
Ranch Hand
Joined: Feb 01, 2007
Posts: 77
|
|
Isn't that a bad practice to have a try {} inside a for loop or any of the loops ? - Harjit
|
 |
Bill Cruise
Ranch Hand
Joined: Jun 01, 2007
Posts: 148
|
|
Harjit, Generally speaking, no, it isn't a bad practice at all. If you want to log the error in accessing or processing a single file then move on to the next one, this is the right way to do it.
|
 |
 |
|
|
subject: Exception handling
|
|
|