Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

This noncompliant code example attempts to distinguish between different exceptional behaviors by looking at the exception's message.:

Code Block
bgColor#FFcccc
try {
    doSomething();
} catch(Exception e) {
  String msg = e.getMessage();
  switch (msg) {
    case "stack underflow":
      // ... 
      break;
    case "connection timeout":
      // ... 
      break;
    case "security violation":
      // ... 
      break;
    default throw e;
  }
}

...