File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Solution:How to skip Exceptions in While Loop and continue. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Solution:How to skip Exceptions in While Loop and continue." Watch "Solution:How to skip Exceptions in While Loop and continue." New topic
Author

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

ram bandakunta
Greenhorn

Joined: Jul 25, 2011
Posts: 4

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

Joined: Oct 25, 2008
Posts: 2700

Hi and welcome to the JavaRanch.

What is your question?


"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
ram bandakunta
Greenhorn

Joined: Jul 25, 2011
Posts: 4

Hi I wanted post the solution for the isuue i faced ,I do not have any question.
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

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!


Retired horse trader.
 Note: double-underline links may be advertisements automatically added by this site and are probably not endorsed by me.
ram bandakunta
Greenhorn

Joined: Jul 25, 2011
Posts: 4

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

Joined: Sep 07, 2004
Posts: 781

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

Joined: Mar 13, 2009
Posts: 492

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


"If the facts don't fit the theory, get new facts" --Albert Einstein
James Sabre
Ranch Hand

Joined: Sep 07, 2004
Posts: 781

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.

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Solution:How to skip Exceptions in While Loop and continue.