• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 4
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
///........................ .........
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi and welcome to the JavaRanch.

What is your question?
 
ram bandakunta
Greenhorn
Posts: 4
Eclipse IDE Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I wanted post the solution for the isuue i faced ,I do not have any question.
 
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Tomcat Server Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 492
Firefox Browser VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic