Re: do loop bug?



emrefan wrote:
Thea wrote:
They both are right.
And... one advice:
*Never ever* use exceptions to control normal program flow.

Point taken. Didn't do that in a real program and will keep from doing
it.

Next thing: catch exactly exception that is thrown.

What if a class of exception are to be caught and there's still a need
to be specific about a single particular one within this class? I
think I'd code thusly if the code to handle this class of exceptions
are much the same except for a tiny variation for "that special one".

Two points:

1. The first applicable cache block gets executed.

catch(EOFException e){
// block 1
}
catch(IOException e){
// block 2
}

runs block 1 for an EOFException, and block 2 for any IOException that
is not an EOFException.

2. If you have common code between two catch blocks you should do
exactly what you should do if you have common code between any two
related blocks in the program, see if you can make it into a method.



Also: continue (label).
In this code labels are not necessary because (as said before) they
cause jump to while statement in loop being executed. They would be
useful if you wanted to jump somewhere else. But I *strongy recommend*
*not* to do such jumps. They introduce lots of confusion and are likely
to cause a lots of bugs that will be diffult to debug because of hard
to predict program's behaviour. Whenever you want to make such jump,
think twice is there is really no other way.
Try to keep your code as short and simple as possible.
That's my advice. Take it or leave it - it's up to you.

Right, avoid goto at all costs? :) Think I will still use it sparsingly
where the identation entailed by the orthodox way gets too much to be
beared.


Over-deep indentation in Java is usually a sign of too much happening in
one method, and a need to refactor.

I don't believe in "avoid goto at all costs". In the decade that I spent
programming mainly in C, I did write a couple of them. However, they
were substitutes for try-finally. So far, I have not missed goto in Java.

I do generally agree with the ideas in Dijkstra's classic "Go To
Statement Considered Harmful" letter, http://www.acm.org/classics/oct95/

Patricia
.



Relevant Pages

  • Re: do loop bug?
    ... *Never ever* use exceptions to control normal program flow. ... cause jump to while statement in loop being executed. ... That's my advice. ...
    (comp.lang.java.programmer)
  • Re: do loop bug?
    ... *Never ever* use exceptions to control normal program flow. ... cause jump to while statement in loop being executed. ... That's my advice. ...
    (comp.lang.java.programmer)
  • Re: rotten egg smell in water heater?
    ... altar nospam wrote: ... Lon's advice allowed for no exceptions. ... Better to "Flush it annually" - even if it doesn't need it - than to assume that your experience is the normal situation. ...
    (rec.outdoors.rv-travel)
  • Re: How to edit an imported solid
    ... threads that you jump into. ... This is a Solidworks newsgroup... ... These users come here for advice so they ... In this particular thread Rocky was searching for a way to get his job ...
    (comp.cad.solidworks)
  • Re: rotten egg smell in water heater?
    ... No more than making a blanket statement that does not always apply. ... Lon's advice allowed for no exceptions. ... assume that your experience is the normal situation. ...
    (rec.outdoors.rv-travel)