DP-3—Unexpected State Not Trapped
- A Case or Switch statement does not include a default case.
- A chain of If/Then/Else statements is not terminated by an unqualified Else statement. Research indicates that 50% to 80% of plain If statements should have an Else clause.
- A default case or the last Else in the chain of If/Then/Else statements does not check for unexpected cases.
- A program may fail silently, in other words, it will continue processing when it should have stopped, with potentially disastrous consequences, such as data corruption or loss.
- Mark any case, switch, and chain of If/Then/Else statements that does not cover all cases.
- Add an Else or a Default case to trap anything other than the explicitly handled cases, OR
- Add a comment explaining why this is not necessary.
- An Analysis of Some Commercial PL/1 Programs (James L. Elshoff), 1976.
Missing "else" for 50-80% of plain "if"s:
50% to 80% of plain "if" statements should have had an "else" clause.