• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception handling

 
Harjit Singh
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 687
Hibernate jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 689
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... 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
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Isn't that a bad practice to have a try {} inside a for loop or any of the loops ?

- Harjit
 
Bill Cruise
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic