switch can contain a default clause for various reason: to handle unexpected values, to show all the cases where properly considered.

For readability purpose, to help a developer to quickly find the default behavior of a switch statement, it is recommended to put the default clause at the beginning or the end of the switch statement. This rule raised an issue if the default statement is not the first or the last one of the switch's cases.

Noncompliant Code Example

switch (param) {
  default: // default clause should be the last one
    error();
    break;
  case 0:
    doSomething();
    break;
  case 1:
    doSomethingElse();
    break;
}

Compliant Solution

switch (param) {
  case 0:
    doSomething();
    break;
  case 1:
    doSomethingElse();
    break;
  default:
    error();
    break;
}

See