Java Reference
In-Depth Information
< Day Day Up >
5. Flow of Control
This section concerns statements that affect flow of control, and exceptions.
5.1. Missing
break
in
switch case
causes fall-through
Prescription:
Don't fall through from one nonempty
case
to another: Terminate each nonempty
case
with a
break
. Document any intentional fall-throughs.
References:
Puzzle 23
; [JLS 14.11].
5.2. It is difficult to terminate an
int
-indexed loop at
Integer.MAX_VALUE
Prescription:
To terminate an
int
-indexed loop at
Integer.MAX_VALUE
, use a
long
loop index or
write the loop very carefully.
References:
Puzzle 26
.
5.3. Abrupt completion of a
finally
block masks pending transfer of
control
Prescription:
Ensure that every
finally
block completes normally, barring a fatal error. Do not
return from or throw an exception from a
finally
block.
References:
Puzzles 36
and
41
; [JLS 14.20.2].
5.4. Using exceptions for normal control flow leads to bugs and poor
performance
Prescription:
Use exceptions only for exceptional cases, never for normal control flow.
References:
Puzzle 42
; [EJ item 39].
< Day Day Up >
Search WWH ::
Custom Search