• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

exception & loop

 
Fernando Dominguez
Ranch Hand
Posts: 106
Debian Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Jaime M. Tovar
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.lang.OutOfMemoryError
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic