A question of Exceptions and loops

E

Enkidu

I'm just beginning to try to understand Exceptions, so this is probably
a naive question.

Suppose I have a class (A) that has a 'while' loop in a method. Within
this loop the method calls a method of another class B. The method call
is within a 'try'. When the Exception occurs in class B the 'catch'
clause in class A is invoked and handled.

In the 'while' loop, if an Exception has occurred, I'd like the loop to
'continue' rather than merely continue on. Is it legitimate to have the
'continue' in the 'catch'?

Or should I set some indicator in the 'catch' and then use an 'if' to
check the indicator and 'continue'?

Or should I restructure the code (which isn't written yet) completely?

Cheers,

Cliff
 
?

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

Enkidu said:
I'm just beginning to try to understand Exceptions, so this is probably
a naive question.

Suppose I have a class (A) that has a 'while' loop in a method. Within
this loop the method calls a method of another class B. The method call
is within a 'try'. When the Exception occurs in class B the 'catch'
clause in class A is invoked and handled.

In the 'while' loop, if an Exception has occurred, I'd like the loop to
'continue' rather than merely continue on. Is it legitimate to have the
'continue' in the 'catch'?

Or should I set some indicator in the 'catch' and then use an 'if' to
check the indicator and 'continue'?

Or should I restructure the code (which isn't written yet) completely?

If you have the catch clause at the bottom of the loop, then
you should not even need continue.

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top