• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Solution:How to skip Exceptions in While Loop and continue.

 
ram bandakunta
Greenhorn
Posts: 4
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following is what i did when I needed to continue through the loop even after getting an exception ,in this there was an invalid stat and we should still subscribe to the valid stat after the invalid stat has thrown an exception .
just added try catch on exception try{
subscribeStat.subcribe(stat);
}
and was able to loop through.
///........................ .........
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi and welcome to the JavaRanch.

What is your question?
 
ram bandakunta
Greenhorn
Posts: 4
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I wanted post the solution for the isuue i faced ,I do not have any question.
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ram bandakunta wrote:Hi I wanted post the solution for the isuue i faced ,I do not have any question.


It's not obvious to me what the issue that you faced is!
 
ram bandakunta
Greenhorn
Posts: 4
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I searched for a solution where there was an exception thrown in a while loop or for loop,in this case i was using an iterator. when the exception is thrown in this case due to an invalid stat the loop could not continue with the processing the other valid stats, all i had to do was to put a try catch inside the for loop .......
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ram bandakunta wrote:I searched for a solution where there was an exception thrown in a while loop or for loop,in this case i was using an iterator. when the exception is thrown in this case due to an invalid stat the loop could not continue with the processing the other valid stats, all i had to do was to put a try catch inside the for loop .......


I'm not sure this makes sense. If uncaught in the loop, an exception thrown inside the loop will automatically cause the loop to exit; no need to catch it inside the loop. What am I missing?
 
Hunter McMillen
Ranch Hand
Posts: 492
Firefox Browser Linux VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The OP doesn't want to exit the loop, they want to catch the exception inside so they can continue iterating through the rest of the data.

Hunter
 
James Sabre
Ranch Hand
Posts: 781
Java Netbeans IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hunter McMillen wrote:The OP doesn't want to exit the loop, they want to catch the exception inside so they can continue iterating through the rest of the data.

Hunter


Looks like I misunderstood "exception is thrown in this case due to an invalid stat the loop could not continue with the processing the other valid stats". I took it to mean that the OP did not want to continue processing the other 'valid stats' but on re-reading I see that it can be read as meaning he did want to continue.

Catching an exception inside a loop is hardly innovative or novel.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic