This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes exception & loop Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "exception & loop" Watch "exception & loop" New topic
Author

exception & loop

Fernando Dominguez
Ranch Hand

Joined: Sep 01, 2006
Posts: 102

while ((itElements.hasNext()))
{
String sElement = (String) itElements.next();
try
{
String sErrorCode = op2.method_ThrowsEx(sElement);
}
catch(Exception e)
{
e.printStackTrace();
}
}

I Know that iterator has 5 elements,
Frist time I call method_throwsEx(sElemtent) an Exception is thrown , stack is printed and the loop ends.

Why does while ends at the frist element?

Does a loop ends when a exception is thrown?

Thans in advanced
bart zagers
Ranch Hand

Joined: Feb 05, 2003
Posts: 234
Originally posted by Fernando Dominguez:

Does a loop ends when a exception is thrown?


Nope, the loop should not end if the exception is catched.
What is the stack-trace that is printed? Are you sure it is from the exception you expect? (The code in the catch can also throw an exception)
Jaime M. Tovar
Ranch Hand

Joined: Mar 28, 2005
Posts: 133
There are throwables that can stop a while loop even if there is a try catch clause. Do you have the stack trace so we can have the detail?


She will remember your heart when men are fairy tales in books written by rabbits.<br /> As long as there is duct tape... there is also hope.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Originally posted by Jaime Tovar:
There are throwables that can stop a while loop even if there is a try catch clause.

Hmm. Can you give an example?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jaime M. Tovar
Ranch Hand

Joined: Mar 28, 2005
Posts: 133
java.lang.OutOfMemoryError
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: exception & loop